From e343beaf6cbd592056ac53986a2f5701f34aafd4 Mon Sep 17 00:00:00 2001 From: Chris Pickslay & Geoff Nix Date: Wed, 22 May 2013 14:06:07 -0700 Subject: [PATCH] Raise error if unable to decode response string --- AFNetworking/AFJSONRequestOperation.m | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/AFNetworking/AFJSONRequestOperation.m b/AFNetworking/AFJSONRequestOperation.m index 6db5f70..2bc3f32 100644 --- a/AFNetworking/AFJSONRequestOperation.m +++ b/AFNetworking/AFJSONRequestOperation.m @@ -76,7 +76,15 @@ static dispatch_queue_t json_request_operation_processing_queue() { // Workaround for a bug in NSJSONSerialization when Unicode character escape codes are used instead of the actual character // See http://stackoverflow.com/a/12843465/157142 NSData *JSONData = [self.responseString dataUsingEncoding:NSUTF8StringEncoding]; - self.responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:self.JSONReadingOptions error:&error]; + + if (JSONData) { + self.responseJSON = [NSJSONSerialization JSONObjectWithData:JSONData options:self.JSONReadingOptions error:&error]; + } else { + //Could not decode response string + error = [[NSError alloc]initWithDomain:AFNetworkingErrorDomain + code:NSURLErrorCannotDecodeContentData + userInfo:@{NSLocalizedDescriptionKey : [NSString stringWithFormat:@"Could not decode:\n%@",self.responseString]}]; + } } self.JSONError = error;