Getting JSON from RetrofitError object using Retrofit

后端 未结 9 1809
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:54

    Using this you can get the error body

      if (response != null && response.errorBody() != null) {
        JSONObject jsonObject = new JSONObject(response.errorBody().string());
        String error =  jsonObject.getString("error");
      }
    

提交回复
热议问题