How to get response body to retrofit exception?

前端 未结 4 1134
梦如初夏
梦如初夏 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 02:56

    Try this code:

    @Override
    public void failure(RetrofitError error) {
        String json =  new String(((TypedByteArray)error.getResponse().getBody()).getBytes());
        Log.v("failure", json.toString());
    }
    

    with Retrofit 2.0

    @Override
    public void onFailure(Call call, Throwable t) {
        String message = t.getMessage();
        Log.d("failure", message);
    }
    

提交回复
热议问题