diff --git a/RACAFNetworking/AFHTTPSessionManager+RACSupport.h b/RACAFNetworking/AFHTTPSessionManager+RACSupport.h index 9a77a25..afbe620 100644 --- a/RACAFNetworking/AFHTTPSessionManager+RACSupport.h +++ b/RACAFNetworking/AFHTTPSessionManager+RACSupport.h @@ -11,6 +11,8 @@ #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 70000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1090) +extern NSString *const RACAFNResponseObjectErrorKey; + @interface AFHTTPSessionManager (RACSupport) /// A convenience around -GET:parameters:success:failure: that returns a cold signal of the @@ -43,4 +45,4 @@ @end -#endif \ No newline at end of file +#endif diff --git a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m index b17997e..e50d8d3 100644 --- a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m +++ b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m @@ -10,6 +10,8 @@ #import "AFHTTPSessionManager+RACSupport.h" +NSString *const RACAFNResponseObjectErrorKey = @"responseObject"; + @implementation AFHTTPSessionManager (RACSupport) - (RACSignal *)rac_GET:(NSString *)path parameters:(id)parameters { @@ -33,7 +35,12 @@ - (RACSignal *)rac_POST:(NSString *)path parameters:(id)parameters constructingB NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - [subscriber sendError:error]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[RACAFNResponseObjectErrorKey] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; [subscriber sendCompleted]; @@ -69,7 +76,12 @@ - (RACSignal *)rac_requestPath:(NSString *)path parameters:(id)parameters method NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - [subscriber sendError:error]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[RACAFNResponseObjectErrorKey] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; [subscriber sendCompleted];