【发布时间】:2019-12-12 07:54:22
【问题描述】:
我有一个 Retrofit 调用,我想在调用 API 时处理 HTTP 和 Retrofit 错误。
因此,当发生故障时,我需要将请求缓存到 RoomDB/SQLite 中,以便当 API 重新联机或连接得到改善时,有一个例程将所有这些请求发送到 API。
x.enqueue(object : Callback<PayloadResponse> {
override fun onResponse(
call: Call<PayloadResponse>,
response: Response<PayloadResponse>
) {
...
val errorMessage = when {
response.code() != HttpURLConnection.HTTP_OK -> {
// Need the original Payload here so I can insert that data into RoomDB/SQLite
"An error occured duing API Call (NOT OK) &{response.code()}"
}
...
我需要 onFailure() 回调的相同情况。
我可以在这些情况下访问原始请求吗?如果有怎么办?
【问题讨论】: