Skip to content
This repository was archived by the owner on Aug 16, 2023. It is now read-only.

Commit 5a485ec

Browse files
committed
Add better handling for Twitter provider.
1 parent 426e690 commit 5a485ec

4 files changed

Lines changed: 62 additions & 9 deletions

File tree

Providers/Twitter/SimpleAuthTwitterProvider.m

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,13 @@ - (RACSignal *)reverseAuthRequestToken {
134134
[subscriber sendCompleted];
135135
}
136136
else {
137-
[subscriber sendError:connectionError];
137+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
138+
if (connectionError) {
139+
dictionary[NSUnderlyingErrorKey] = connectionError;
140+
}
141+
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
142+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
143+
[subscriber sendError:error];
138144
}
139145
}];
140146
return nil;
@@ -165,11 +171,22 @@ - (RACSignal *)remoteAccountWithSystemAccount:(ACAccount *)account {
165171
[subscriber sendCompleted];
166172
}
167173
else {
168-
[subscriber sendNext:parseError];
174+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
175+
if (parseError) {
176+
dictionary[NSUnderlyingErrorKey] = parseError;
177+
}
178+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorInvalidData userInfo:dictionary];
179+
[subscriber sendNext:error];
169180
}
170181
}
171182
else {
172-
[subscriber sendError:connectionError];
183+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
184+
if (connectionError) {
185+
dictionary[NSUnderlyingErrorKey] = connectionError;
186+
}
187+
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
188+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
189+
[subscriber sendError:error];
173190
}
174191
}];
175192
return nil;
@@ -196,7 +213,13 @@ - (RACSignal *)accessTokenWithReverseAuthRequestToken:(NSString *)token account:
196213
[subscriber sendCompleted];
197214
}
198215
else {
199-
[subscriber sendError:connectionError];
216+
NSMutableDictionary *dictionary = [NSMutableDictionary new];
217+
if (connectionError) {
218+
dictionary[NSUnderlyingErrorKey] = connectionError;
219+
}
220+
dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
221+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorNetwork userInfo:dictionary];
222+
[subscriber sendError:error];
200223
}
201224
}];
202225
return nil;

SimpleAuth/ACAccountStore+SimpleAuth.m

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
// Copyright (c) 2014 Seesaw Decisions Corporation. All rights reserved.
77
//
88

9+
#import "SimpleAuth.h"
910
#import "ACAccountStore+SimpleAuth.h"
1011
#import <ReactiveCocoa/ReactiveCocoa.h>
1112

@@ -25,20 +26,28 @@ + (RACSignal *)SimpleAuth_accountsWithTypeIdentifier:(NSString *)typeIdentifier
2526
return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber) {
2627
ACAccountStore *store = [self SimpleAuth_sharedAccountStore];
2728
ACAccountType *type = [store accountTypeWithAccountTypeIdentifier:typeIdentifier];
28-
[store requestAccessToAccountsWithType:type options:options completion:^(BOOL granted, NSError *error) {
29+
[store requestAccessToAccountsWithType:type options:options completion:^(BOOL granted, NSError *accountsError) {
2930
if (granted) {
3031
NSArray *accounts = [store accountsWithAccountType:type];
3132
NSUInteger numberOfAccounts = [accounts count];
3233
if (numberOfAccounts == 0) {
33-
[subscriber sendError:(error ?: [[NSError alloc] initWithDomain:ACErrorDomain code:ACErrorAccountNotFound userInfo:nil])];
34+
NSDictionary *dictionary = @{
35+
NSUnderlyingErrorKey: accountsError ?: [[NSError alloc] initWithDomain:ACErrorDomain code:ACErrorAccountNotFound userInfo:nil]
36+
};
37+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorAccounts userInfo:dictionary];
38+
[subscriber sendError:error];
3439
}
3540
else {
3641
[subscriber sendNext:accounts];
3742
[subscriber sendCompleted];
3843
}
3944
}
4045
else {
41-
[subscriber sendError:(error ?: [[NSError alloc] initWithDomain:ACErrorDomain code:ACErrorPermissionDenied userInfo:nil])];
46+
NSDictionary *dictionary = @{
47+
NSUnderlyingErrorKey: accountsError ?: [[NSError alloc] initWithDomain:ACErrorDomain code:ACErrorPermissionDenied userInfo:nil]
48+
};
49+
NSError *error = [NSError errorWithDomain:SimpleAuthErrorDomain code:SimpleAuthErrorAccounts userInfo:dictionary];
50+
[subscriber sendError:error];
4251
}
4352
}];
4453
return nil;

SimpleAuth/SimpleAuth.h

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,28 @@
77
//
88

99
extern NSString * const SimpleAuthErrorDomain;
10-
enum {
11-
SimpleAuthErrorUserCancelled
10+
extern NSString * const SimpleAuthErrorStatusCodeKey;
11+
typedef NS_ENUM(NSUInteger, SimpleAuthError) {
12+
13+
/**
14+
The user cancelled authentication.
15+
*/
16+
SimpleAuthErrorUserCancelled,
17+
18+
/*
19+
An error that occurred as the result of a failed network operation.
20+
*/
21+
SimpleAuthErrorNetwork,
22+
23+
/**
24+
An error that originated in Accounts.framework.
25+
*/
26+
SimpleAuthErrorAccounts,
27+
28+
/**
29+
Returned if SimpleAuth was able to parse response data.
30+
*/
31+
SimpleAuthErrorInvalidData
1232
};
1333

1434
/**

SimpleAuth/SimpleAuth.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
NSString * const SimpleAuthPresentInterfaceBlockKey = @"present_interface_block";
2020
NSString * const SimpleAuthDismissInterfaceBlockKey = @"dismiss_interface_block";
2121
NSString * const SimpleAuthRedirectURIKey = @"redirect_uri";
22+
NSString * const SimpleAuthErrorStatusCodeKey = @"SimpleAuthErrorStatusCode";
2223

2324
static SimpleAuthProvider *__currentProvider = nil;
2425

0 commit comments

Comments
 (0)