Skip to content

Commit

Permalink
Don't wrap authorisation errors as the are already wrapped in a domain
Browse files Browse the repository at this point in the history
specific error, just create an unknown error if we aren't authorised
and don't have an error.
  • Loading branch information
lukeredpath committed Jun 11, 2012
1 parent 2ae56b1 commit 4ccf788
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions Library/PTPusher.m
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
{
NSString *scheme = ((encrypted == YES) ? @"wss" : @"ws");
NSString *URLString = [NSString stringWithFormat:@"%@://%@/app/%@?client=%@&protocol=%d&version=%f",
scheme, host, key, clientID, kPTPusherClientProtocolVersion, kPTPusherClientLibraryVersion];
scheme, host, key, clientID, kPTPusherClientProtocolVersion, kPTPusherClientLibraryVersion];
return [NSURL URLWithString:URLString];
}

Expand Down Expand Up @@ -66,11 +66,11 @@ - (id)initWithConnection:(PTPusherConnection *)connection connectAutomatically:(
if (self = [super init]) {
dispatcher = [[PTPusherEventDispatcher alloc] init];
channels = [[NSMutableDictionary alloc] init];

authorizationQueue = [[NSOperationQueue alloc] init];
authorizationQueue.maxConcurrentOperationCount = 5;
authorizationQueue.name = @"com.pusher.libPusher.authorizationQueue";

self.connection = connection;
self.connection.delegate = self;

Expand Down Expand Up @@ -219,19 +219,15 @@ - (void)unsubscribeFromChannel:(PTPusherChannel *)channel

- (void)subscribeToChannel:(PTPusherChannel *)channel
{
[channel authorizeWithCompletionHandler:^(BOOL isAuthorized, NSDictionary *authData, NSError *underlyingError) {
[channel authorizeWithCompletionHandler:^(BOOL isAuthorized, NSDictionary *authData, NSError *error) {
if (isAuthorized && self.connection.isConnected) {
[channel subscribeWithAuthorization:authData];
}
else {
NSMutableDictionary *userInfo = [NSMutableDictionary dictionary];

if (underlyingError) {
[userInfo setObject:underlyingError forKey:NSUnderlyingErrorKey];
if (error == nil) {
error = [NSError errorWithDomain:PTPusherErrorDomain code:PTPusherSubscriptionUnknownAuthorisationError userInfo:nil];
}

NSError *error = [NSError errorWithDomain:PTPusherErrorDomain code:PTPusherSubscriptionAuthorisationError userInfo:userInfo];

if ([self.delegate respondsToSelector:@selector(pusher:didFailToSubscribeToChannel:withError:)]) {
[self.delegate pusher:self didFailToSubscribeToChannel:channel withError:error];
}
Expand Down Expand Up @@ -314,9 +310,9 @@ - (void)pusherConnection:(PTPusherConnection *)connection didReceiveEvent:(PTPus
[dispatcher dispatchEvent:event];

[[NSNotificationCenter defaultCenter]
postNotificationName:PTPusherEventReceivedNotification
object:self
userInfo:[NSDictionary dictionaryWithObject:event forKey:PTPusherEventUserInfoKey]];
postNotificationName:PTPusherEventReceivedNotification
object:self
userInfo:[NSDictionary dictionaryWithObject:event forKey:PTPusherEventUserInfoKey]];
}

- (void)handleDisconnection:(PTPusherConnection *)connection error:(NSError *)error
Expand Down

0 comments on commit 4ccf788

Please sign in to comment.