How to get response body to retrofit exception?

前端 未结 4 1139
梦如初夏
梦如初夏 2021-02-01 02:12

I am trying to connect to rest service via retrofit in android application. I am getting responses. But when there is some error response from the service, conversion exception

4条回答
  •  余生分开走
    2021-02-01 03:02

    Your server should return 4xx HTTP error code to get this working.

    When your server returns HTTP 200 this mean successful response and it will be processed with onSuccess branch. Likely your object which you pass to Callback should be ready to handle both success and error result.

    To make sure this is the case you can check if RetrofitError is actually a JsonParseException by adding next snippet:

    public void failure(RetrofitError error) {
        Log.v(TAG, error.getMessage());
    };
    

    提交回复
    热议问题