Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -61,21 +61,25 @@ - (void)_taskDidFinish {
return;
}

if ([result isKindOfClass:[NSDictionary class]]) {
NSDictionary *resultDictionary = (NSDictionary *)result;
if (resultDictionary[@"error"]) {
NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary];
errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400);
self.error = [PFErrorUtilities errorFromResult:errorDictionary];
[super _taskDidFinish];
return;
if (self.response.statusCode >= 200) {
if (self.response.statusCode < 400) {
PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result
resultString:resultString
httpResponse:self.response];
self.result = commandResult;
} else if ([result isKindOfClass:[NSDictionary class]]) {
NSDictionary *resultDictionary = (NSDictionary *)result;
if (resultDictionary[@"error"]) {
NSMutableDictionary *errorDictionary = [NSMutableDictionary dictionaryWithDictionary:resultDictionary];
errorDictionary[@"temporary"] = @(self.response.statusCode >= 500 || self.response.statusCode < 400);
self.error = [PFErrorUtilities errorFromResult:errorDictionary];
}
}
}

PFCommandResult *commandResult = [PFCommandResult commandResultWithResult:result
resultString:resultString
httpResponse:self.response];
self.result = commandResult;
if (!self.result && !self.error) {
self.error = [PFErrorUtilities errorWithCode:kPFErrorInternalServer message:resultString];
}
[super _taskDidFinish];
}

Expand Down
10 changes: 5 additions & 5 deletions Tests/Unit/URLSessionDataTaskDelegateTests.m
Original file line number Diff line number Diff line change
Expand Up @@ -70,11 +70,11 @@ - (void)testSuccess {
NSData *chunkA = [@"{ \"foo\" :" dataUsingEncoding:NSUTF8StringEncoding];
NSData *chunkB = [@" \"bar\" }" dataUsingEncoding:NSUTF8StringEncoding];

NSURLResponse *urlResponse = [[NSURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"]
MIMEType:@"application/json"
expectedContentLength:chunkA.length + chunkB.length
textEncodingName:@"UTF-8"];

NSHTTPURLResponse *urlResponse = [[NSHTTPURLResponse alloc] initWithURL:[NSURL URLWithString:@"http://foo.bar"]
statusCode:200
HTTPVersion:@"HTTP/1.1"
headerFields:nil];
[delegate URLSession:mockedSession
task:mockedTask
didSendBodyData:5
Expand Down
Loading