Permalink
Browse files

Updated SDNetTask.h/m to support new error types:

- SDNetTaskErrorAuthenticationCanceled
- SDNetTaskErrorAuthenticationFailed
- SDNetTaskErrorNotConnectedToInternet

For reasons I don't get, when authentication fails, the NSError's error
code is SDNetTaskErrorAuthenticationCanceled whenever I use an incorrect
password
  • Loading branch information...
1 parent 965eff9 commit f35d408978bd074d025b15300c798eabeff35bb0 @catsby catsby committed May 27, 2010
Showing with 21 additions and 3 deletions.
  1. +3 −0 Source/SDNetTask.h
  2. +18 −3 Source/SDNetTask.m
View
@@ -19,6 +19,9 @@ typedef enum _SDNetTaskError {
SDNetTaskErrorParserFailed,
SDNetTaskErrorParserDataIsNil,
SDNetTaskErrorServiceDefinedError,
+ SDNetTaskErrorAuthenticationCanceled,
+ SDNetTaskErrorAuthenticationFailed,
+ SDNetTaskErrorNotConnectedToInternet,
SDNetTaskErrorMAX // once again, don't touch.
} SDNetTaskError;
View
@@ -116,14 +116,25 @@ - (void) main {
if (connectionError) {
underlyingError = connectionError;
-
// commented out the next line because some APIs are using HTTP error codes as return values, which is super lame
// errorCode = SDNetTaskErrorConnectionFailed;
// [self _sendResultsToDelegate];
// return;
}
+ switch ([underlyingError code]) {
+ case NSURLErrorUserCancelledAuthentication:
+ errorCode = SDNetTaskErrorAuthenticationCanceled;
+ break;
+ case NSURLErrorUserAuthenticationRequired:
+ errorCode = SDNetTaskErrorAuthenticationFailed;
+ break;
+ case NSURLErrorNotConnectedToInternet:
+ errorCode = SDNetTaskErrorNotConnectedToInternet;
+ break;
+ }
+
if (data == nil) {
errorCode = SDNetTaskErrorConnectionDataIsNil;
[self _sendResultsToDelegate];
@@ -151,6 +162,7 @@ - (void) main {
errorCode = SDNetTaskErrorParserFailed;
underlyingError = errorFromParser;
}
+
else if (results == nil)
errorCode = SDNetTaskErrorParserDataIsNil;
@@ -167,8 +179,7 @@ - (void) _sendResultsToDelegateFromMainThread {
if (errorCode == SDNetTaskErrorNone) {
[self sendResultsToDelegate];
- }
- else {
+ } else {
// we'll create our error manually and let the delegate get all touchy-feely with it all they want
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];
@@ -347,6 +358,10 @@ - (NSString*) errorString {
errorStrings[SDNetTaskErrorConnectionFailed] = @"Connection failed with error";
errorStrings[SDNetTaskErrorParserFailed] = @"Parser failed with error";
errorStrings[SDNetTaskErrorParserDataIsNil] = @"Parser returned NULL data";
+ errorStrings[SDNetTaskErrorAuthenticationCanceled] = @"Authentication request cancelled";
+ errorStrings[SDNetTaskErrorAuthenticationFailed] = @"Authentication failed";
+ errorStrings[SDNetTaskErrorNotConnectedToInternet] = @"No internet connection established";
+
return errorStrings[errorCode];
}

0 comments on commit f35d408

Please sign in to comment.