Retrofit2 Handle condition when status code 200 but json structure different than datamodel class

后端 未结 5 448
-上瘾入骨i
-上瘾入骨i 2021-02-01 22:09

I\'m using Retrofit2 and RxJava2CallAdapterFactory.

The API I consume returns status code always as 200 and for success and response JSON string the JSON st

5条回答
  •  情深已故
    2021-02-01 22:54

    You can simply do that by doing this

    try
    {
    String error = response.errorBody().string();
    error = error.replace("\"", "");
    Toast.makeText(getContext(), error, Toast.LENGTH_LONG).show();
    }
    catch (IOException e)
    {
    e.printStackTrace();
    }
    

提交回复
热议问题