@@ -27,7 +27,6 @@ public final class BucketManager {
2727 * Configuration 对象
2828 * 该类相关的域名配置,解析配置,HTTP请求超时时间设置等
2929 */
30-
3130 private Configuration configuration ;
3231
3332 /**
@@ -90,19 +89,32 @@ public static String encodedEntry(String bucket) {
9089 public String [] buckets () throws QiniuException {
9190 // 获取 bucket 列表 写死用rs.qiniu.com or rs.qbox.me @冯立元
9291 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 ;
9599 }
96100
97101 public void createBucket (String bucketName , String region ) throws QiniuException {
98102 String url = String .format ("%s/mkbucketv2/%s/region/%s" , configuration .rsHost (),
99103 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 ();
101109 }
102110
103111 public void deleteBucket (String bucketname ) throws QiniuException {
104112 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 ();
106118 }
107119
108120 /**
@@ -114,8 +126,13 @@ public void deleteBucket(String bucketname) throws QiniuException {
114126 */
115127 public String [] domainList (String bucket ) throws QiniuException {
116128 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 ;
119136 }
120137
121138 /**
@@ -389,7 +406,6 @@ public FetchRet fetch(String url, String bucket, String key) throws QiniuExcepti
389406 * @return Response
390407 * @throws QiniuException
391408 */
392-
393409 public Response asynFetch (String url , String bucket , String key ) throws QiniuException {
394410 String requesturl = configuration .apiHost (auth .accessKey , bucket ) + "/sisyphus/fetch" ;
395411 StringMap stringMap = new StringMap ().put ("url" , url ).put ("bucket" , bucket ).putNotNull ("key" , key );
0 commit comments