Skip to content

Commit ece5f0b

Browse files
authored
Merge pull request #258 from zshbleaker/master
Fix problem of no callback when no network.
2 parents 107eb96 + a115b00 commit ece5f0b

File tree

4 files changed

+18
-2
lines changed

4 files changed

+18
-2
lines changed

library/library.iml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -112,4 +112,4 @@
112112
<orderEntry type="library" exported="" name="okhttp-3.2.0" level="project" />
113113
<orderEntry type="library" exported="" name="happy-dns-0.2.7" level="project" />
114114
</component>
115-
</module>
115+
</module>

library/src/main/java/com/qiniu/android/common/AutoZone.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,10 @@ public void complete(ResponseInfo info, JSONObject response) {
9898
e.printStackTrace();
9999
complete.onFailure(ResponseInfo.NetworkError);
100100
}
101+
} else {
102+
if (info.isNetworkBroken()) {
103+
complete.onFailure(info.statusCode);
104+
}
101105
}
102106
}
103107
});

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,16 @@ public static ResponseInfo fileError(Exception e, final UpToken upToken) {
160160
return create(null, InvalidFile, "", "", "", "", "", "", 80, 0, 0, e.getMessage(), upToken);
161161
}
162162

163+
public static ResponseInfo networkError(int code, UpToken upToken) {
164+
return create(null, code, "", "", "", "", "", "", 80, 0, 0, "Network error during preQuery", upToken);
165+
}
166+
167+
public static boolean isStatusCodeForBrokenNetwork(int code) {
168+
return code == NetworkError || code == UnknownHost
169+
|| code == CannotConnectToHost || code == TimedOut
170+
|| code == NetworkConnectionLost;
171+
}
172+
163173
public boolean isCancelled() {
164174
return statusCode == Cancelled;
165175
}

library/src/main/java/com/qiniu/android/storage/UploadManager.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -95,7 +95,9 @@ public void onSuccess() {
9595

9696
@Override
9797
public void onFailure(int reason) {
98-
final ResponseInfo info = ResponseInfo.invalidToken("invalid token");
98+
final ResponseInfo info = ResponseInfo.isStatusCodeForBrokenNetwork(reason) ?
99+
ResponseInfo.networkError(reason, decodedToken) :
100+
ResponseInfo.invalidToken("invalid token");
99101
completionHandler.complete(key, info, null);
100102
}
101103
});

0 commit comments

Comments
 (0)