How do I get Response body when there is an error when using Retrofit 2.0 Observables

前端 未结 3 1739
眼角桃花
眼角桃花 2021-01-31 16:13

I am using Retrofit 2.0 to make api calls that return Observables. It all works good when the call went through fine and the response is as expected. Now let\'s say we have an e

3条回答
  •  星月不相逢
    2021-01-31 16:39

    Just check if the throwable is an instance of HttpException and then you can access the retrofit response

    if (e instanceof HttpException) {
        ResponseBody body = ((HttpException) e).response().errorBody();
        ...
    }
    

    Then you can use the converter to deserialize it (or do it yourself).

提交回复
热议问题