Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HTTP code 204 causes *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil' #32

Open
alusev opened this issue Jun 29, 2015 · 6 comments

Comments

@alusev
Copy link

alusev commented Jun 29, 2015

I have the following construction:

    [[UNIRest get:^(UNISimpleRequest *request) {
        [request setUrl:url];
        [request setHeaders:headers];
    }] asJsonAsync:^(UNIHTTPJsonResponse* response, NSError *error) {
    }];

Sometimes a web service returns HTTP "204 No Content" with an empty message-body. It causes the error in json-searilization:

id json = [NSJSONSerialization JSONObjectWithData:[httpResponse rawBody] options:NSJSONReadingMutableLeaves error:&error];

in UNIHTTPJsonResponse implementation.

Plus, it returns HTTP status code 0, instead of 204.

 *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
*** First throw call stack:
(
    0   CoreFoundation                      0x000000010df73c65 __exceptionPreprocess + 165
    1   libobjc.A.dylib                     0x000000010dc0cbb7 objc_exception_throw + 45
    2   CoreFoundation                      0x000000010df73b9d +[NSException raise:format:] + 205
    3   Foundation                          0x000000010d8a97ef +[NSJSONSerialization JSONObjectWithData:options:error:] + 67
    4   MYAPP                              0x000000010bbdaef5 -[UNIHTTPJsonResponse initWithSimpleResponse:] + 453
    5   MYAPP                              0x000000010bbdbfe8 __30-[UNIHTTPRequest asJsonAsync:]_block_invoke + 200
    6   MYAPP                              0x000000010bbdaac3 __44+[UNIHTTPClientHelper requestAsync:handler:]_block_invoke + 179
    7   MYAPP                              0x000000010bbdebd9 __47-[UNIUrlConnection connectionDidFinishLoading:]_block_invoke + 89
    8   Foundation                          0x000000010d84557f __NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK__ + 7
    9   Foundation                          0x000000010d7860b2 -[NSBlockOperation main] + 98
    10  Foundation                          0x000000010d768774 -[__NSOperationInternal _start:] + 645
    11  Foundation                          0x000000010d768383 __NSOQSchedule_f + 184
    12  libdispatch.dylib                   0x000000010e586614 _dispatch_client_callout + 8
    13  libdispatch.dylib                   0x000000010e56d6a7 _dispatch_queue_drain + 2176
    14  libdispatch.dylib                   0x000000010e56ccc0 _dispatch_queue_invoke + 235
    15  libdispatch.dylib                   0x000000010e5703b9 _dispatch_root_queue_drain + 1359
    16  libdispatch.dylib                   0x000000010e571b17 _dispatch_worker_thread3 + 111
    17  libsystem_pthread.dylib             0x000000010e8f3637 _pthread_wqthread + 729
    18  libsystem_pthread.dylib             0x000000010e8f140d start_wqthread + 13
)
libc++abi.dylib: terminating with uncaught exception of type NSException
@alusev
Copy link
Author

alusev commented Jul 1, 2015

Same problem with HTTP status code 401. The library returns status 0.

@alusev
Copy link
Author

alusev commented Jul 10, 2015

A pull-request #31 fixes it.

@gamorejon
Copy link

I seem to still be getting return status 0 on 401s when I build with pull-request #31.

@alusev
Copy link
Author

alusev commented Dec 30, 2015

Are you sure you’ve loaded it the pull-request #31? I’ve used it in a couple of projects and I've never had a problem with it.

@joarleymoraes
Copy link

It worked fine for me with pull-request #31. Thanks.

@idixcom
Copy link

idixcom commented Mar 5, 2019

Any plans to roll this fix into a new Podspec? Not sure if this library is still supported. Thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants