From 06d2e944cdcc975b67c39f0de8d7f2c10019b2f5 Mon Sep 17 00:00:00 2001 From: Ray Shih Date: Fri, 6 Feb 2015 16:03:09 +0800 Subject: [PATCH 1/4] add responseObject to error.userInfo --- RACAFNetworking/AFHTTPSessionManager+RACSupport.m | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m index b17997e..568c1f0 100644 --- a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m +++ b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m @@ -33,7 +33,10 @@ - (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]; + userInfo[@"responseObject"] = 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 +72,10 @@ - (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]; + userInfo[@"responseObject"] = responseObject; + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; [subscriber sendCompleted]; From dbcad3f98b767c9171f8341d41ed6f76074d7b81 Mon Sep 17 00:00:00 2001 From: Ray Shih Date: Fri, 6 Feb 2015 17:38:24 +0800 Subject: [PATCH 2/4] check responseObject to prevent crash --- .../AFHTTPSessionManager+RACSupport.m | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m index 568c1f0..83f2853 100644 --- a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m +++ b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m @@ -33,9 +33,11 @@ - (RACSignal *)rac_POST:(NSString *)path parameters:(id)parameters constructingB NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - userInfo[@"responseObject"] = responseObject; - NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[@"responseObject"] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; @@ -72,9 +74,11 @@ - (RACSignal *)rac_requestPath:(NSString *)path parameters:(id)parameters method NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - userInfo[@"responseObject"] = responseObject; - NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[@"responseObject"] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; From 1c0a9f3d003582fa4210acf7662dcaddd64a0558 Mon Sep 17 00:00:00 2001 From: Ray Shih Date: Fri, 6 Feb 2015 22:49:51 +0800 Subject: [PATCH 3/4] adjust indent format --- .../AFHTTPSessionManager+RACSupport.m | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m index 83f2853..1d5a8b7 100644 --- a/RACAFNetworking/AFHTTPSessionManager+RACSupport.m +++ b/RACAFNetworking/AFHTTPSessionManager+RACSupport.m @@ -33,11 +33,11 @@ - (RACSignal *)rac_POST:(NSString *)path parameters:(id)parameters constructingB NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if (responseObject) { - userInfo[@"responseObject"] = responseObject; - } - NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[@"responseObject"] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; @@ -74,11 +74,11 @@ - (RACSignal *)rac_requestPath:(NSString *)path parameters:(id)parameters method NSURLSessionDataTask *task = [self dataTaskWithRequest:request completionHandler:^(NSURLResponse *response, id responseObject, NSError *error) { if (error) { - NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; - if (responseObject) { - userInfo[@"responseObject"] = responseObject; - } - NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; + NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; + if (responseObject) { + userInfo[@"responseObject"] = responseObject; + } + NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes]; } else { [subscriber sendNext:RACTuplePack(responseObject, response)]; From 8f17b8b3f32d497e2f4974e3cfef0b08a3498d9c Mon Sep 17 00:00:00 2001 From: Ray Shih Date: Fri, 6 Feb 2015 23:22:05 +0800 Subject: [PATCH 4/4] add constant RACAFNResponseObjectErrorKey --- RACAFNetworking/AFHTTPSessionManager+RACSupport.h | 4 +++- RACAFNetworking/AFHTTPSessionManager+RACSupport.m | 6 ++++-- 2 files changed, 7 insertions(+), 3 deletions(-) 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 1d5a8b7..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 { @@ -35,7 +37,7 @@ - (RACSignal *)rac_POST:(NSString *)path parameters:(id)parameters constructingB if (error) { NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; if (responseObject) { - userInfo[@"responseObject"] = responseObject; + userInfo[RACAFNResponseObjectErrorKey] = responseObject; } NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes]; @@ -76,7 +78,7 @@ - (RACSignal *)rac_requestPath:(NSString *)path parameters:(id)parameters method if (error) { NSMutableDictionary *userInfo = [error.userInfo mutableCopy]; if (responseObject) { - userInfo[@"responseObject"] = responseObject; + userInfo[RACAFNResponseObjectErrorKey] = responseObject; } NSError *errorWithRes = [NSError errorWithDomain:error.domain code:error.code userInfo:[userInfo copy]]; [subscriber sendError:errorWithRes];