【发布时间】:2018-04-13 00:12:58
【问题描述】:
也许我不懂 apis 或 Retrofit2,但是当我收到 500 Internal Server Error 时,我想适当地通知用户。
当我在收到此错误后记录传入的响应时,当我像这样记录时得到null:
Gson g = new Gson();
Log.d(TAG, g.toJson(response.errorBody()));
但是,当我记录我的回复时,我会在 rawResponse 中看到 code、message 等,如下所示:
(为简洁起见,部分 JSON 已被删除)
{
"rawResponse":{
"body":{
"contentLength":0,
"contentType":{
"mediaType":"text/html",
"subtype":"html",
"type":"text"
}
},
"code":500,
"headers":{
"namesAndValues":[ ]
},
"message":"Internal Server Error",
"networkResponse":{
"code":500,
"headers":{ },
"message":"Internal Server Error",
"protocol":"HTTP_1_1",
"receivedResponseAtMillis":1509415428600,
"request":{ },
"sentRequestAtMillis":1509415428428
},
"protocol":"HTTP_1_1",
"receivedResponseAtMillis":1509415428600,
"request":{ },
"sentRequestAtMillis":1509415428428
}
}
所以我不明白的是,response.errorBody 是从哪里得出的?
【问题讨论】:
标签: android error-handling response retrofit2