Skip to content

Commit 18a507f

Browse files
committed
Merge pull request #147 from ParsePlatform/nlutsenko.errors
Fixed error on network requests to Object APIs with 'error' column.
2 parents 9c8b6fd + 61c10a5 commit 18a507f

File tree

4 files changed

+129
-126
lines changed

4 files changed

+129
-126
lines changed

Parse/Internal/Commands/CommandRunner/URLSession/Session/TaskDelegate/PFURLSessionJSONDataTaskDelegate.m

Lines changed: 16 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -61,21 +61,25 @@ - (void)_taskDidFinish {
6161
return;
6262
}
6363

64-
if ([result isKindOfClass:[NSDictionary class]]) {
65-
NSDictionary *resultDictionary = (NSDictionary *)result;
66-
if (resultDictionary[@"error"]) {
67-
NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary];
68-
errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400);
69-
self.error = [PFErrorUtilities errorFromResult:errorDictionary];
70-
[super _taskDidFinish];
71-
return;
64+
if (self.response.statusCode >= 200) {
65+
if (self.response.statusCode < 400) {
66+
PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result
67+
resultString:resultString
68+
httpResponse:self.response];
69+
self.result = commandResult;
70+
} else if ([result isKindOfClass:[NSDictionary class]]) {
71+
NSDictionary *resultDictionary = (NSDictionary *)result;
72+
if (resultDictionary[@"error"]) {
73+
NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary];
74+
errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400);
75+
self.error = [PFErrorUtilities errorFromResult:errorDictionary];
76+
}
7277
}
7378
}
7479

75-
PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result
76-
resultString:resultString
77-
httpResponse:self.response];
78-
self.result = commandResult;
80+
if (!self.result && !self.error) {
81+
self.error = [PFErrorUtilities errorWithCode:kPFErrorInternalServer message:resultString];
82+
}
7983
[super _taskDidFinish];
8084
}
8185

Tests/Unit/URLSessionDataTaskDelegateTests.m

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,11 @@ - (void)testSuccess {
7070
NSData *chunkA = [@"{ \"foo\" :" dataUsingEncoding:NSUTF8StringEncoding];
7171
NSData *chunkB = [@" \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding];
7272

73-
NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"]
74-
MIMEType:@"application/json"
75-
expectedContentLength:chunkA.length + chunkB.length
76-
textEncodingName:@"UTF-8"];
77-
73+
NSHTTPURLResponse *urlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"]
74+
statusCode:200
75+
HTTPVersion:@"HTTP/1.1"
76+
headerFields:nil];
77+
7878
[delegate URLSession:mockedSession
7979
task:mockedTask
8080
didSendBodyData:5

0 commit comments

Comments
 (0)