Skip to content

Instantly share code, notes, and snippets.

@sspencer
Created August 1, 2012 01:57
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sspencer/3222686 to your computer and use it in GitHub Desktop.
Save sspencer/3222686 to your computer and use it in GitHub Desktop.
Override MKNetworkOperation so 4xx response body available in the error handler
// Register your NetworkOperation class after creating your network engine
// someEngine = [[SomeEngine alloc] initWithHostName:SOME_API customHeaderFields:nil];
// [someEngine registerOperationSubclass:[SomeNetworkOperation class]];
// ------ SomeNetworkOperation.h ------
#import "MKNetworkOperation.h"
@interface SomeNetworkOperation : MKNetworkOperation
@end
// ------ SomeNetworkOperation.m ------
#import "SomeNetworkOperation.h"
@implementation SomeNetworkOperation
-(void) operationFailedWithError:(NSError*) error
{
NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
[userInfo setObject:[self responseString] forKey:@"responseString"];
[super operationFailedWithError:[NSError errorWithDomain:NSURLErrorDomain code:error.code userInfo:userInfo]];
}
@end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment