Skip to content

Commit 47f9adf

Browse files
author
YangSen-qn
committed
throw Exception while read response error
1 parent 1f0fb9f commit 47f9adf

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

src/main/java/com/qiniu/http/Client.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,7 +425,8 @@ public void accept(String key, Object value) {
425425

426426
double duration = (System.currentTimeMillis() - start) / 1000.0;
427427
r = Response.create(res, tag.ip, duration);
428-
if (r.statusCode >= 300) {
428+
// 如果读取 body 失败也抛出异常
429+
if (r.statusCode >= 300 || !StringUtils.isNullOrEmpty(r.error)) {
429430
throw new QiniuException(r);
430431
}
431432

src/main/java/com/qiniu/http/Response.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,20 @@ private String getMethod(okhttp3.Response response) {
8585
return method;
8686
}
8787

88+
89+
/***
90+
* 构造请求方法,此处可能会尝试读取 body,如果 body 读取失败会保留原始的
91+
* 状态码,因此判断请求是否成功使用 Response.isOK()
92+
* <p>
93+
* SDK 内部处理:
94+
* 同步请求,请求失败会抛异常
95+
* 异步请求,判断请求是否成功使用 Response.isOK()
96+
*
97+
* @param response okhttp3 请求 response
98+
* @param address 请求 address
99+
* @param duration 请求耗时
100+
* @return com.qiniu.http.Response 七牛 Response
101+
**/
88102
public static Response create(okhttp3.Response response, String address, double duration) {
89103
String error = null;
90104
int code = response.code();

0 commit comments

Comments
 (0)