rx java retrofit 2 error handling

后端 未结 3 1680
無奈伤痛
無奈伤痛 2020-12-31 23:36

I\'m using retrofit 2 along with rx java

Situation: the app sends some request, then i get the response in json-format that is automatically converted to User dto,

3条回答
  •  轮回少年
    2021-01-01 00:12

    I had the same situation and the way I could get the json from the server when an error occurs was something like this:

    retrofit2.Response r = call.execute();
    
    String errorMessage = "";
    try {
        errorMessage = r.errorBody().string();
    } catch (IOException e) {
        e.printStackTrace();
    }
    Timber.d("errorMessage: " + errorMessage);
    

提交回复
热议问题