Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

There doesn't seem to be a way to retrieve response data for when a connection fails #80

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion Sources/OAuth2Client/NXOAuth2Client.m
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,12 @@ - (void)oauthConnection:(NXOAuth2Connection *)connection didFailWithError:(NSErr
NSString *body = [[NSString alloc] initWithData:connection.data encoding:NSUTF8StringEncoding];
NSLog(@"oauthConnection Error: %@", body);

NSMutableDictionary *userInfo = [NSMutableDictionary dictionaryWithDictionary:error.userInfo];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In this case you should reference the old error in the userInfo with NSUnderlyingErrorKey.

if (connection.data) {
[userInfo setObject:connection.data forKey:NXOAuth2ErrorResponseDataKey];
}

NSError *updatedError = [NSError errorWithDomain:error.domain code:error.code userInfo:[NSDictionary dictionaryWithDictionary:userInfo]];
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[NSDictionary dictionaryWithDictionary:userInfo] or just [userInfo copy]


if (connection == authConnection) {
self.authenticating = NO;
Expand Down Expand Up @@ -539,7 +545,7 @@ - (void)oauthConnection:(NXOAuth2Connection *)connection didFailWithError:(NSErr
}

if ([delegate respondsToSelector:@selector(oauthClient:didFailToGetAccessTokenWithError:)]) {
[delegate oauthClient:self didFailToGetAccessTokenWithError:error];
[delegate oauthClient:self didFailToGetAccessTokenWithError:updatedError];
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OAuth2Client/NXOAuth2Constants.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,4 +106,4 @@ typedef enum {


extern NSString * const NXOAuth2AccountStoreErrorKey;

extern NSString * const NXOAuth2ErrorResponseDataKey;
1 change: 1 addition & 0 deletions Sources/OAuth2Client/NXOAuth2Constants.m
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@
#pragma mark UserInfo Keys

NSString * const NXOAuth2AccountStoreErrorKey = @"NXOAuth2AccountStoreErrorKey";
NSString * const NXOAuth2ErrorResponseDataKey = @"NXOAuth2ErrorResponseDataKey";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a \n at the end.