Skip to content

Instantly share code, notes, and snippets.

@debuggerman
Created August 10, 2011 09:50
Show Gist options
  • Save debuggerman/1136478 to your computer and use it in GitHub Desktop.
Save debuggerman/1136478 to your computer and use it in GitHub Desktop.
handling response
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