Skip to content
This repository was archived by the owner on May 14, 2024. It is now read-only.

Commit fe38fcf

Browse files
committed
distinguish between handshake failed and unauthorized handshake
1 parent 1dd831e commit fe38fcf

File tree

3 files changed

+13
-6
lines changed

3 files changed

+13
-6
lines changed

SocketIO.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ typedef enum {
3939
SocketIOWebSocketClosed = -4,
4040
SocketIOTransportsNotSupported = -5,
4141
SocketIOHandshakeFailed = -6,
42-
SocketIODataCouldNotBeSend = -7
42+
SocketIODataCouldNotBeSend = -7,
43+
SocketIOUnauthorized = -8
4344
} SocketIOErrorCodes;
4445

4546

SocketIO.m

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -684,6 +684,8 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
684684
{
685685
NSLog(@"ERROR: handshake failed ... %@", [error localizedDescription]);
686686

687+
int errorCode = [error code] == 403 ? SocketIOUnauthorized : SocketIOHandshakeFailed;
688+
687689
_isConnected = NO;
688690
_isConnecting = NO;
689691

@@ -692,7 +694,7 @@ - (void) connection:(NSURLConnection *)connection didFailWithError:(NSError *)er
692694
forKey:NSUnderlyingErrorKey] mutableCopy];
693695

694696
NSError *err = [NSError errorWithDomain:SocketIOError
695-
code:SocketIOHandshakeFailed
697+
code:errorCode
696698
userInfo:errorInfo];
697699

698700
[_delegate socketIO:self onError:err];

SocketTesterARC/ViewController.m

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ - (void) viewDidLoad
3737
nil];
3838
NSHTTPCookie *cookie = [NSHTTPCookie cookieWithProperties:properties];
3939
NSArray *cookies = [NSArray arrayWithObjects:cookie, nil];
40-
40+
4141
socketIO.cookies = cookies;
42-
42+
4343
// connect to the socket.io server that is running locally at port 3000
4444
[socketIO connectToHost:@"localhost" onPort:3000];
4545
}
@@ -55,7 +55,7 @@ - (void) socketIODidConnect:(SocketIO *)socket
5555
- (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet
5656
{
5757
NSLog(@"didReceiveEvent()");
58-
58+
5959
SocketIOCallback cb = ^(id argsData) {
6060
NSDictionary *response = argsData;
6161
// do something with response
@@ -69,7 +69,11 @@ - (void) socketIO:(SocketIO *)socket didReceiveEvent:(SocketIOPacket *)packet
6969

7070
- (void) socketIO:(SocketIO *)socket onError:(NSError *)error
7171
{
72-
NSLog(@"onError() %@", error);
72+
if ([error code] == SocketIOUnauthorized) {
73+
NSLog(@"not authorized");
74+
} else {
75+
NSLog(@"onError() %@", error);
76+
}
7377
}
7478

7579

0 commit comments

Comments
 (0)