Skip to content
This repository has been archived by the owner on Nov 14, 2017. It is now read-only.

Commit

Permalink
Merge pull request #41 from rayshih/master
Browse files Browse the repository at this point in the history
add responseObject to error.userInfo
  • Loading branch information
CodaFi committed Feb 6, 2015
2 parents 0435f4f + 8f17b8b commit 1c14917
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
4 changes: 3 additions & 1 deletion RACAFNetworking/AFHTTPSessionManager+RACSupport.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -43,4 +45,4 @@

@end

#endif
#endif
16 changes: 14 additions & 2 deletions RACAFNetworking/AFHTTPSessionManager+RACSupport.m
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@

#import "AFHTTPSessionManager+RACSupport.h"

NSString *const RACAFNResponseObjectErrorKey = @"responseObject";

@implementation AFHTTPSessionManager (RACSupport)

- (RACSignal *)rac_GET:(NSString *)path parameters:(id)parameters {
Expand All @@ -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];
Expand Down Expand Up @@ -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];
Expand Down

0 comments on commit 1c14917

Please sign in to comment.