Skip to content

Commit 8575fa1

Browse files
committed
Merge pull request #36 from longbai/status_code
status_code
2 parents 73c331a + 5b347c2 commit 8575fa1

File tree

1 file changed

+55
-4
lines changed

1 file changed

+55
-4
lines changed

QiniuSDK/Http/QNResponseInfo.m

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,55 @@
1414
const int kQNRequestCancelled = -2;
1515
const int kQNNetworkError = -1;
1616

17+
/**
18+
https://developer.apple.com/library/ios/documentation/Cocoa/Reference/Foundation/Miscellaneous/Foundation_Constants/index.html#//apple_ref/doc/constant_group/URL_Loading_System_Error_Codes
19+
20+
NSURLErrorUnknown = -1,
21+
NSURLErrorCancelled = -999,
22+
NSURLErrorBadURL = -1000,
23+
NSURLErrorTimedOut = -1001,
24+
NSURLErrorUnsupportedURL = -1002,
25+
NSURLErrorCannotFindHost = -1003,
26+
NSURLErrorCannotConnectToHost = -1004,
27+
NSURLErrorDataLengthExceedsMaximum = -1103,
28+
NSURLErrorNetworkConnectionLost = -1005,
29+
NSURLErrorDNSLookupFailed = -1006,
30+
NSURLErrorHTTPTooManyRedirects = -1007,
31+
NSURLErrorResourceUnavailable = -1008,
32+
NSURLErrorNotConnectedToInternet = -1009,
33+
NSURLErrorRedirectToNonExistentLocation = -1010,
34+
NSURLErrorBadServerResponse = -1011,
35+
NSURLErrorUserCancelledAuthentication = -1012,
36+
NSURLErrorUserAuthenticationRequired = -1013,
37+
NSURLErrorZeroByteResource = -1014,
38+
NSURLErrorCannotDecodeRawData = -1015,
39+
NSURLErrorCannotDecodeContentData = -1016,
40+
NSURLErrorCannotParseResponse = -1017,
41+
NSURLErrorInternationalRoamingOff = -1018,
42+
NSURLErrorCallIsActive = -1019,
43+
NSURLErrorDataNotAllowed = -1020,
44+
NSURLErrorRequestBodyStreamExhausted = -1021,
45+
NSURLErrorFileDoesNotExist = -1100,
46+
NSURLErrorFileIsDirectory = -1101,
47+
NSURLErrorNoPermissionsToReadFile = -1102,
48+
NSURLErrorSecureConnectionFailed = -1200,
49+
NSURLErrorServerCertificateHasBadDate = -1201,
50+
NSURLErrorServerCertificateUntrusted = -1202,
51+
NSURLErrorServerCertificateHasUnknownRoot = -1203,
52+
NSURLErrorServerCertificateNotYetValid = -1204,
53+
NSURLErrorClientCertificateRejected = -1205,
54+
NSURLErrorClientCertificateRequired = -1206,
55+
NSURLErrorCannotLoadFromNetwork = -2000,
56+
NSURLErrorCannotCreateFile = -3000,
57+
NSURLErrorCannotOpenFile = -3001,
58+
NSURLErrorCannotCloseFile = -3002,
59+
NSURLErrorCannotWriteToFile = -3003,
60+
NSURLErrorCannotRemoveFile = -3004,
61+
NSURLErrorCannotMoveFile = -3005,
62+
NSURLErrorDownloadDecodingFailedMidStream = -3006,
63+
NSURLErrorDownloadDecodingFailedToComplete = -3007
64+
*/
65+
1766
static QNResponseInfo *cancelledInfo = nil;
1867

1968
static NSString *domain = @"qiniu.com";
@@ -29,9 +78,11 @@ + (instancetype)responseInfoWithInvalidArgument:(NSString *)text {
2978
}
3079

3180
+ (instancetype)responseInfoWithNetError:(NSError *)error host:(NSString *)host duration:(double)duration {
32-
if (error.code != -1003) {
81+
int code = kQNNetworkError;
82+
if (error != nil) {
83+
code = (int)error.code;
3384
}
34-
return [[QNResponseInfo alloc] initWithStatus:kQNNetworkError error:error host:host duration:duration];
85+
return [[QNResponseInfo alloc] initWithStatus:code error:error host:host duration:duration];
3586
}
3687

3788
+ (instancetype)responseInfoWithFileError:(NSError *)error {
@@ -124,11 +175,11 @@ - (BOOL)isConnectionBroken {
124175
}
125176

126177
- (BOOL)needSwitchServer {
127-
return _statusCode == kQNNetworkError || (_statusCode / 100 == 5 && _statusCode != 579);
178+
return _statusCode == kQNNetworkError || (_statusCode < -1000 && _statusCode != -1003) || (_statusCode / 100 == 5 && _statusCode != 579);
128179
}
129180

130181
- (BOOL)couldRetry {
131-
return (_statusCode >= 500 && _statusCode < 600 && _statusCode != 579) || _statusCode == kQNNetworkError || _statusCode == 996 || _statusCode == 406 || (_statusCode == 200 && _error != nil);
182+
return (_statusCode >= 500 && _statusCode < 600 && _statusCode != 579) || _statusCode == kQNNetworkError || _statusCode == 996 || _statusCode == 406 || (_statusCode == 200 && _error != nil) || _statusCode < -1000;
132183
}
133184

134185
@end

0 commit comments

Comments
 (0)