Skip to content

Commit a99d23f

Browse files
committed
修复重试判断
1 parent 37fa91b commit a99d23f

File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed

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

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,11 @@ public boolean isOK() {
9292
return statusCode == 200 && error == null && reqId != null;
9393
}
9494

95+
9596
public boolean isNetworkBroken() {
96-
return statusCode == NetworkError;
97+
return statusCode == NetworkError || statusCode == UnknownHost
98+
|| statusCode == CannotConnectToHost || statusCode == TimedOut
99+
|| statusCode == NetworkConnectionLost;
97100
}
98101

99102
public boolean isServerError() {
@@ -102,16 +105,15 @@ public boolean isServerError() {
102105
}
103106

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

110111
public boolean needRetry() {
111-
return !isCancelled() && (isNetworkBroken() || isServerError() || statusCode == 406
112+
return !isCancelled() && (needSwitchServer() || statusCode == 406
112113
|| (statusCode == 200 && error != null));
113114
}
114115

116+
115117
public String toString() {
116118
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}",
117119
super.toString(), statusCode, reqId, xlog, xvia, host, ip, port, duration, error);

0 commit comments

Comments
 (0)