Created
August 10, 2011 09:50
-
-
Save debuggerman/1136478 to your computer and use it in GitHub Desktop.
handling response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
if(mStatusCode == StatusCodeCreated || mStatusCode == StatusCodeUpdated) { | |
[mBaseDelegate handleAPIResult]; | |
} else { | |
NSError *newError = nil; | |
NSError *jsonError = nil; | |
NSDictionary *resultDict = [[CJSONDeserializer deserializer] deserializeAsDictionary:mReceivedData error:&jsonError]; | |
SMLog(@"%@", resultDict); | |
NSDictionary *errorDict = [resultDict objectForKey:@"validation_result"]; | |
if(errorDict != nil) { | |
NSArray *errorFields = [errorDict objectForKey:@"error_fields"]; | |
if(errorFields != nil || [errorFields count] > 0) { | |
NSString *errorField = [errorFields objectAtIndex:0]; | |
NSString *errorMessage = [[errorDict objectForKey:@"error_messages"] objectForKey:errorField]; | |
if(errorMessage == nil || [errorMessage length] == 0) | |
errorMessage = NSLocalizedString(@"internalServerError",@""); | |
NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:errorMessage, NSLocalizedDescriptionKey, nil]; | |
newError = [[NSError alloc] initWithDomain:kMyErrorDomain code:kMyErrorCode userInfo:errorDict]; | |
} | |
} | |
if(newError == nil) { | |
NSString *errorString = [NSString stringWithFormat:NSLocalizedString(@"internalServerError",@""), mStatusCode]; | |
NSDictionary *errorDict = [NSDictionary dictionaryWithObjectsAndKeys:errorString, NSLocalizedDescriptionKey, nil]; | |
newError = [[NSError alloc] initWithDomain:kMyErrorDomain code:NSURLErrorUnknown userInfo:errorDict]; | |
} | |
[mBaseDelegate handleAPIResultError:newError]; | |
SMSaveRelease(newError); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment