- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我在带有 Retrofit 和 OKHttp 的 Android 上使用 Robospice。使用 Robospice RequestListener 将响应传递回 Activity ,一切都很好。问题是它只在连接超时或其他网络问题时返回失败。如果返回 401,则它被归类为成功,但响应为空,因为它无法将 JSON 解析到我们的 MobileAppSetup POJO 中。
目前我必须对响应进行空检查,但我不知道是服务器错误还是有效的 401 是什么原因。
public final class HTTPRequestListener implements RequestListener<MobileAppSetup> {
@Override
public void onRequestFailure(SpiceException spiceException) {
Log.d("", "failure:"+ spiceException);
loginProgress.hide();
}
@Override
public void onRequestSuccess(final MobileAppSetup response) {
Log.d("","success. Data: "+response);
if(response==null)
showDialog("Error logging in", "Please check your username and password and try again.", "");
loginProgress.hide();
postLoginProcess(response);
}
}
我需要将这些错误传递给 onRequestFailure 回调,以便我可以正确处理它。有没有一种方法可以指定 Robospice 应将其视为错误的错误代码。我认为它涉及添加某种自定义错误处理程序,但目前确实找不到解决方案。
最佳答案
这是由于 OKHTTP 客户端 中的错误 possible bug !
Problem is When the server answers with a 401 Unauthorized responses, the Callback object calls its failure() method..
When the server returns with the 401 status, the
RetrofitError
response object is null, and thenetworkError
flag is set to true, making it impossible for the app to checkerror.getResponse().getStatus()
I believe the error lies on the http client. When using OkClient I get this error: java.io.IOException: No authentication challenges found
我建议你从 square/okhttp 下载新的 okhttp jar 文件再次运行项目!或尝试使用任何其他客户端而不是 okhttp。
关于android - 我如何让 Robospice 将来自 Retrofit 和 OKHttp 的 200 响应以外的任何其他内容视为错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22633415/
我是一名优秀的程序员,十分优秀!