This repository was archived by the owner on May 14, 2024. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Expand file tree Collapse file tree 1 file changed +21
-0
lines changed Original file line number Diff line number Diff line change @@ -171,6 +171,27 @@ - (void) poll:(NSString *)data retryNumber:(int)retry
171
171
172
172
- (void ) connection : (NSURLConnection *)connection didReceiveResponse : (NSURLResponse *)response
173
173
{
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
+
174
195
[_data setLength: 0 ];
175
196
}
176
197
You can’t perform that action at this time.
0 commit comments