I\'m using Retrofit to make a POST Request in my web server.
However, I can\'t seem to get the response body when the response status is 422 (unprocessable entit
By default, when your server is returning an error code response.body()
is always null
. What you are looking for is response.errorBody()
. A common approach would be something like this:
@Override
public void onResponse(Response response, Retrofit retrofit) {
if (response.isSuccess()) {
response.body(); // do something with this
} else {
response.errorBody(); // do something with that
}
}
If you need something advanced take a look at Interceptors and how to use them