Skip to content

Commit 7a6ee0b

Browse files
committed
* fixed: jsonmodel#319
* fixed: jsonmodel#313
1 parent e7386f0 commit 7a6ee0b

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

JSONModel/JSONModelNetworking/JSONHTTPClient.m

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,14 @@ +(NSData*)syncRequestDataFromURL:(NSURL*)url method:(NSString*)method requestBod
190190
//turn off network indicator
191191
if (doesControlIndicator) dispatch_async(dispatch_get_main_queue(), ^{[self setNetworkIndicatorVisible:NO];});
192192

193+
//special case for http error code 401
194+
if ([*err code] == kCFURLErrorUserCancelledAuthentication) {
195+
response = [[NSHTTPURLResponse alloc] initWithURL:url
196+
statusCode:401
197+
HTTPVersion:@"HTTP/1.1"
198+
headerFields:@{}];
199+
}
200+
193201
//if not OK status set the err to a JSONModelError instance
194202
if (response.statusCode >= 300 || response.statusCode < 200) {
195203
//create a new error
@@ -301,13 +309,13 @@ +(void)JSONFromURLWithString:(NSString*)urlString method:(NSString*)method param
301309
}
302310

303311
//step 3: if there's no response so far, return a basic error
304-
if (!responseData && !jsonObject) {
312+
if (!responseData && !error) {
305313
//check for false response, but no network error
306314
error = [JSONModelError errorBadResponse];
307315
}
308316

309317
//step 4: if there's a response at this and no errors, convert to object
310-
if (error==nil && jsonObject==nil) {
318+
if (error==nil) {
311319
// Note: it is possible to have a valid response with empty response data (204 No Content).
312320
// So only create the JSON object if there is some response data.
313321
if(responseData.length > 0)

0 commit comments

Comments
 (0)