Skip to content

Commit c3891f2

Browse files
committed
Merge pull request #117 from simon-liubin/fix/needRetry
修复重试判断
2 parents 37fa91b + f314706 commit c3891f2

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

library/src/main/java/com/qiniu/android/http/ResponseInfo.java

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -91,9 +91,11 @@ public boolean isCancelled() {
9191
public boolean isOK() {
9292
return statusCode == 200 && error == null && reqId != null;
9393
}
94-
94+
9595
public boolean isNetworkBroken() {
96-
return statusCode == NetworkError;
96+
return statusCode == NetworkError || statusCode == UnknownHost
97+
|| statusCode == CannotConnectToHost || statusCode == TimedOut
98+
|| statusCode == NetworkConnectionLost;
9799
}
98100

99101
public boolean isServerError() {
@@ -102,16 +104,15 @@ public boolean isServerError() {
102104
}
103105

104106
public boolean needSwitchServer() {
105-
return statusCode == NetworkError || statusCode == CannotConnectToHost
106-
|| statusCode == TimedOut || statusCode == NetworkConnectionLost
107-
|| (statusCode >= 500 && statusCode < 600 && statusCode != 579);
107+
return isNetworkBroken() || isServerError();
108108
}
109109

110110
public boolean needRetry() {
111-
return !isCancelled() && (isNetworkBroken() || isServerError() || statusCode == 406
111+
return !isCancelled() && (needSwitchServer() || statusCode == 406
112112
|| (statusCode == 200 && error != null));
113113
}
114114

115+
115116
public String toString() {
116117
return String.format(Locale.ENGLISH, "{ResponseInfo:%s,status:%d, reqId:%s, xlog:%s, xvia:%s, host:%s, ip:%s, port:%d, duration:%f s, error:%s}",
117118
super.toString(), statusCode, reqId, xlog, xvia, host, ip, port, duration, error);

0 commit comments

Comments
 (0)