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

Commit 9e03bce

Browse files
author
Allen Schober
committed
check HTTP status code of NSURLConnection responses during xhr polling transport just like when checking HTTP status code during handshake. Handles case when server restarts while connection with device is already established.
1 parent b28b395 commit 9e03bce

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

SocketIOTransportXHR.m

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,27 @@ - (void) poll:(NSString *)data retryNumber:(int)retry
171171

172172
- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
173173
{
174+
// check for server status code (http://gigliwood.com/weblog/Cocoa/Q__When_is_an_conne.html)
175+
if ([response respondsToSelector:@selector(statusCode)]) {
176+
NSInteger statusCode = [((NSHTTPURLResponse *)response) statusCode];
177+
DEBUGLOG(@"didReceiveResponse() %i", statusCode);
178+
179+
if (statusCode >= 400) {
180+
// stop connecting; no more delegate messages
181+
[connection cancel];
182+
183+
NSString *error = [NSString stringWithFormat:NSLocalizedString(@"Server returned status code %d", @""), statusCode];
184+
NSDictionary *errorInfo = [NSDictionary dictionaryWithObject:error forKey:NSLocalizedDescriptionKey];
185+
NSError *statusError = [NSError errorWithDomain:SocketIOError
186+
code:statusCode
187+
userInfo:errorInfo];
188+
189+
if ([delegate respondsToSelector:@selector(onError:)]) {
190+
[delegate onError:statusError];
191+
}
192+
}
193+
}
194+
174195
[_data setLength:0];
175196
}
176197

0 commit comments

Comments
 (0)