@@ -107,8 +107,7 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
107107 [CMDQueryStringSerialization queryStringWithDictionary: parameters]];
108108 NSURL *URL = [NSURL URLWithString: URLString];
109109 NSURLRequest *request = [NSURLRequest requestWithURL: URL];
110- [NSURLConnection sendAsynchronousRequest: request queue: self .operationQueue
111- completionHandler: ^(NSURLResponse *response, NSData *data, NSError *connectionError) {
110+ [NSURLConnection sendAsynchronousRequest: request queue: self .operationQueue completionHandler: ^(NSURLResponse *response, NSData *data, NSError *connectionError) {
112111 NSIndexSet *indexSet = [NSIndexSet indexSetWithIndexesInRange: NSMakeRange (200 , 99 )];
113112 NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode ];
114113 if ([indexSet containsIndex: statusCode] && data) {
@@ -119,11 +118,22 @@ - (RACSignal *)accountWithAccessToken:(NSDictionary *)accessToken {
119118 [subscriber sendCompleted ];
120119 }
121120 else {
122- [subscriber sendError: parseError];
121+ NSMutableDictionary *dictionary = [NSMutableDictionary new ];
122+ if (parseError) {
123+ dictionary[NSUnderlyingErrorKey ] = parseError;
124+ }
125+ NSError *error = [NSError errorWithDomain: SimpleAuthErrorDomain code: SimpleAuthErrorInvalidData userInfo: dictionary];
126+ [subscriber sendNext: error];
123127 }
124128 }
125129 else {
126- [subscriber sendError: connectionError];
130+ NSMutableDictionary *dictionary = [NSMutableDictionary new ];
131+ if (connectionError) {
132+ dictionary[NSUnderlyingErrorKey ] = connectionError;
133+ }
134+ dictionary[SimpleAuthErrorStatusCodeKey] = @(statusCode);
135+ NSError *error = [NSError errorWithDomain: SimpleAuthErrorDomain code: SimpleAuthErrorNetwork userInfo: dictionary];
136+ [subscriber sendError: error];
127137 }
128138 }];
129139 return nil ;
0 commit comments