Skip to content

Instantly share code, notes, and snippets.

@iandundas
Last active September 11, 2018 09:02
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save iandundas/c952249d343a75350972 to your computer and use it in GitHub Desktop.
Save iandundas/c952249d343a75350972 to your computer and use it in GitHub Desktop.
How to get response body in an AFNetworking failure block #AFNetworking
// I can never, ever remember how to do this, so here's how:
failure:^(AFHTTPRequestOperation *operation, NSError *error) {
NSData *data= error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey];
NSString *failureResponse = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
NSLog(@"Failure response: %@", failureResponse);
}
@iandundas
Copy link
Author

Can also do it like this, if server returns error in plaintext:

failure:^(AFHTTPRequestOperation *operation, NSError *error) {
        NSLog(@"Response from server: %@", operation.responseString);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment