square / retrofit

A type-safe HTTP client for Android and the JVM
https://square.github.io/retrofit/
Apache License 2.0
43.03k stars 7.3k forks source link

body part of response is null #1709

Closed zincle closed 8 years ago

zincle commented 8 years ago

Use of compile 'com.squareup.retrofit2:retrofit:2.0.1' compile 'com.squareup.retrofit2:converter-gson:2.0.1'

Case 1st.. When we send status of api hit to be (200) (that is successful) Our response is parsed properly, and we get our body by calling "response.body()"

Case 2nd.. When we send status of api to be (400) (that is unsuccessful), our body part is not parsed by convertor and it comes out to be "null", and we get "response.body()" comes out to be null. and apart from this "error.errorBody()" is not giving body content (in JSON format) that is sent from the server.

zincle commented 8 years ago

Basically in case of error, the response body is not parsed as well as the error body also does not show data sent from server.

JakeWharton commented 8 years ago

Basically in case of error, the response body is not parsed

This is expected and as documented.

the error body also does not show data sent from server.

There is a test which verifies the error body is available: https://github.com/square/retrofit/blob/011a89ee00e16d6e775b29fa4710718cc864baf8/retrofit/src/test/java/retrofit2/CallTest.java#L105-L118. Are you sure your server is returning a non-empty body?

Can you supply a failing test case that demonstrates your problem?

herau commented 7 years ago

from the javadoc of the Response.bodymethod.

The deserialized response body of a successful response.

Your API should mention that the result could be null i guess.