Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Handle responses with no content (ex. http status code 204) #9

Merged
merged 1 commit into from

2 participants

@dstnbrkr

Ran into an issue where AFJSONRequestOperation tries to parse empty response data, which in turn causes JSONKit to raise an NSInvalidArgumentException, reason: 'The string argument is NULL.'

This patch checks for 0 length data before attempting to parse.

@dstnbrkr dstnbrkr Call success with nil if response data has length == 0.
Fixes exception when attempting to parse empty response data (i.e. HTTP Status Code 204 No Content).
fa0297f
@mattt mattt merged commit d22ed88 into AFNetworking:master
@mattt

Many thanks for your patch, Dustin. I really appreciate it!

@dedmons dedmons referenced this pull request from a commit
Commit has since been removed from the repository and is no longer available.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2011
  1. @dstnbrkr

    Call success with nil if response data has length == 0.

    dstnbrkr authored
    Fixes exception when attempting to parse empty response data (i.e. HTTP Status Code 204 No Content).
This page is out of date. Refresh to see the latest.
Showing with 4 additions and 0 deletions.
  1. +4 −0 AFNetworking/AFJSONRequestOperation.m
View
4 AFNetworking/AFJSONRequestOperation.m
@@ -61,6 +61,10 @@ + (id)operationWithRequest:(NSURLRequest *)urlRequest
if (failure) {
failure(error);
}
+ } else if ([data length] == 0) {
+ if (success) {
+ success(nil);
+ }
} else {
id JSON = nil;
Something went wrong with that request. Please try again.