Getting JSON from RetrofitError object using Retrofit

后端 未结 9 1808
Happy的楠姐
Happy的楠姐 2020-12-24 01:39

I am using the Retrofit library to do REST calls to a service I am using.

If I make an API call to my service and have a failure, the service returns a bit of JSON

9条回答
  •  陌清茗
    陌清茗 (楼主)
    2020-12-24 01: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);
    }
    

提交回复
热议问题