Getting JSON from RetrofitError object using Retrofit

后端 未结 9 1807
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 02:03

    @LukaCiko answer not working now for me in retrofit 1.6.1. Here like I'm doing it now:

        @Override
        public void failure(RetrofitError retrofitError) {
            String json =  new String(((TypedByteArray)retrofitError.getResponse().getBody()).getBytes());
            //own logic for example
            ExampleHandlerError error = new Gson().fromJson(json, ExampleHandlerError.class);
        }
    

提交回复
热议问题