我路过null
现在,这会导致崩溃!
参见:val response: Response<ReviewResponse> = Response.error(-1, null)
代码:
suspend fun getReviewData() = getResult {
try {
apiService.getReviewData(getCustomerId())
} catch (e: Exception) {
val response: Response<ReviewResponse> = Response.error(-1, null)
response
}
}
正如你所看到的,null 在内部不接受,我必须传递这个:ResponseBody body
最佳答案
这个怎么样:
Response.error(404, ResponseBody.create(null, "Not found response body"))
关于java - 如何创建 OkHttp 所需的虚拟 ResponseBody 对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71393447/