forked from Hackmodford/HMFJSONResponseSerializerWithData
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathHMFJSONResponseSerializerWithData.m
More file actions
29 lines (23 loc) · 1.07 KB
/
HMFJSONResponseSerializerWithData.m
File metadata and controls
29 lines (23 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
//
// HMFJSONResponseSerializerWithData.m
//
// Created by Brandon Butler on 10/15/13.
// Copyright (c) 2013 Brandon Butler. All rights reserved.
//
#import "HMFJSONResponseSerializerWithData.h"
@implementation HMFJSONResponseSerializerWithData
- (id)responseObjectForResponse:(NSURLResponse *)response
data:(NSData *)data
error:(NSError *__autoreleasing *)error
{
id JSONObject = [super responseObjectForResponse:response data:data error:error]; // may mutate `error`
if (*error != nil) {
NSMutableDictionary *userInfo = [(*error).userInfo mutableCopy];
[userInfo setValue:[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding] forKey:JSONResponseSerializerWithDataKey];
[userInfo setValue:[response valueForKey:JSONResponseSerializerWithBodyKey] forKey:JSONResponseSerializerWithBodyKey];
NSError *newError = [NSError errorWithDomain:(*error).domain code:(*error).code userInfo:userInfo];
(*error) = newError;
}
return JSONObject;
}
@end