From 3f5fef0671c92d00b0faf594096c6b0c60b6260a Mon Sep 17 00:00:00 2001 From: Caleb Davenport Date: Tue, 30 Sep 2014 09:53:23 -0700 Subject: [PATCH] Add better error handling to Facebook provider. --- Providers/Facebook/SimpleAuthFacebookProvider.m | 15 +++++++++++++-- Providers/Twitter/SimpleAuthTwitterProvider.m | 15 +++++++++++++-- 2 files changed, 26 insertions(+), 4 deletions(-) diff --git a/Providers/Facebook/SimpleAuthFacebookProvider.m b/Providers/Facebook/SimpleAuthFacebookProvider.m index b41a02c..224731d 100644 --- a/Providers/Facebook/SimpleAuthFacebookProvider.m +++ b/Providers/Facebook/SimpleAuthFacebookProvider.m @@ -83,11 +83,22 @@ - (RACSignal *)remoteAccountWithSystemAccount:(ACAccount *)account { [subscriber sendCompleted]; } else { - [subscriber sendError:parseError]; + NSMutableDictionary *dictionary = [NSMutableDictionary new]; + if (parseError) { + dictionary[NSUnderlyingErrorKey] = parseError; + } + NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary]; + [subscriber sendNext:error]; } } else { - [subscriber sendError:connectionError]; + NSMutableDictionary *dictionary = [NSMutableDictionary new]; + if (connectionError) { + dictionary[NSUnderlyingErrorKey] = connectionError; + } + dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode); + NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary]; + [subscriber sendError:error]; } }]; return nil; diff --git a/Providers/Twitter/SimpleAuthTwitterProvider.m b/Providers/Twitter/SimpleAuthTwitterProvider.m index 485a2aa..3898ed2 100644 --- a/Providers/Twitter/SimpleAuthTwitterProvider.m +++ b/Providers/Twitter/SimpleAuthTwitterProvider.m @@ -357,11 +357,22 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken { [subscriber sendCompleted]; } else { - [subscriber sendError:parseError]; + NSMutableDictionary *dictionary = [NSMutableDictionary new]; + if (parseError) { + dictionary[NSUnderlyingErrorKey] = parseError; + } + NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary]; + [subscriber sendNext:error]; } } else { - [subscriber sendError:connectionError]; + NSMutableDictionary *dictionary = [NSMutableDictionary new]; + if (connectionError) { + dictionary[NSUnderlyingErrorKey] = connectionError; + } + dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode); + NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary]; + [subscriber sendError:error]; } }]; return nil;