@@ -27,7 +27,6 @@ public final class BucketManager {
27
27
* Configuration 对象
28
28
* 该类相关的域名配置,解析配置,HTTP请求超时时间设置等
29
29
*/
30
-
31
30
private Configuration configuration ;
32
31
33
32
/**
@@ -90,19 +89,32 @@ public static String encodedEntry(String bucket) {
90
89
public String [] buckets () throws QiniuException {
91
90
// 获取 bucket 列表 写死用rs.qiniu.com or rs.qbox.me @冯立元
92
91
String url = String .format ("%s/buckets" , configuration .rsHost ());
93
- Response r = get (url );
94
- return r .jsonToObject (String [].class );
92
+ Response res = get (url );
93
+ if (!res .isOK ()) {
94
+ throw new QiniuException (res );
95
+ }
96
+ String [] buckets = res .jsonToObject (String [].class );
97
+ res .close ();
98
+ return buckets ;
95
99
}
96
100
97
101
public void createBucket (String bucketName , String region ) throws QiniuException {
98
102
String url = String .format ("%s/mkbucketv2/%s/region/%s" , configuration .rsHost (),
99
103
UrlSafeBase64 .encodeToString (bucketName ), region );
100
- post (url , null ).close ();
104
+ Response res = post (url , null );
105
+ if (!res .isOK ()) {
106
+ throw new QiniuException (res );
107
+ }
108
+ res .close ();
101
109
}
102
110
103
111
public void deleteBucket (String bucketname ) throws QiniuException {
104
112
String url = String .format ("%s/drop/%s" , configuration .rsHost (), bucketname );
105
- post (url , null ).close ();
113
+ Response res = post (url , null );
114
+ if (!res .isOK ()) {
115
+ throw new QiniuException (res );
116
+ }
117
+ res .close ();
106
118
}
107
119
108
120
/**
@@ -114,8 +126,13 @@ public void deleteBucket(String bucketname) throws QiniuException {
114
126
*/
115
127
public String [] domainList (String bucket ) throws QiniuException {
116
128
String url = String .format ("%s/v6/domain/list?tbl=%s" , configuration .apiHost (), bucket );
117
- Response r = get (url );
118
- return r .jsonToObject (String [].class );
129
+ Response res = get (url );
130
+ if (!res .isOK ()) {
131
+ throw new QiniuException (res );
132
+ }
133
+ String [] domains = res .jsonToObject (String [].class );
134
+ res .close ();
135
+ return domains ;
119
136
}
120
137
121
138
/**
@@ -389,7 +406,6 @@ public FetchRet fetch(String url, String bucket, String key) throws QiniuExcepti
389
406
* @return Response
390
407
* @throws QiniuException
391
408
*/
392
-
393
409
public Response asynFetch (String url , String bucket , String key ) throws QiniuException {
394
410
String requesturl = configuration .apiHost (auth .accessKey , bucket ) + "/sisyphus/fetch" ;
395
411
StringMap stringMap = new StringMap ().put ("url" , url ).put ("bucket" , bucket ).putNotNull ("key" , key );
0 commit comments