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

Commit d12c7a1

Browse files
committed
Merge commit '9e03bceb0df9e4ee20f787e3c01897b53b515e30' into develop
2 parents c53d069 + 9e03bce commit d12c7a1

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)