We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
设置 builder.callTimeout(1, TimeUnit.SECONDS); 之后不会执行到 AbsCallback 里面的 onError
builder.callTimeout(1, TimeUnit.SECONDS);
AbsCallback
onError
OkHttpClient.Builder builder = new OkHttpClient.Builder(); builder.callTimeout(1, TimeUnit.SECONDS); OkHttpClient okHttpClient = builder.build(); OkGo.<T>post(url) .client(okHttpClient) ... .execute(AbsCallback);
protected void requestNetworkAsync() { rawCall.enqueue(new okhttp3.Callback() { @Override public void onFailure(okhttp3.Call call, IOException e) { if (e instanceof SocketTimeoutException && currentRetryCount < request.getRetryCount()) { //retry when timeout currentRetryCount++; rawCall = request.getRawCall(); if (canceled) { rawCall.cancel(); } else { rawCall.enqueue(this); } } else { if (!call.isCanceled()) { // 问题出在这里 Response<T> error = Response.error(false, call, null, e); onError(error); } } } @Override public void onResponse(okhttp3.Call call, okhttp3.Response response) throws IOException { int responseCode = response.code(); //network error if (responseCode == 404 || responseCode >= 500) { Response<T> error = Response.error(false, call, response, HttpException.NET_ERROR()); onError(error); return; } if (onAnalysisResponse(call, response)) return; try { T body = request.getConverter().convertResponse(response); //save cache when request is successful saveCache(response.headers(), body); Response<T> success = Response.success(false, body, call, response); onSuccess(success); } catch (Throwable throwable) { Response<T> error = Response.error(false, call, response, throwable); onError(error); } } }); }
问题出在这里: if (!call.isCanceled()) { // 问题出在这里
当 callTimeout 在 okHttp 里面被触发的时候,IOException 是: java.io.InterruptedIOException: timeout
并且 RealCall.this.isCanceled() 返回 true 所以就没有机会调用到指定的 onError 回调了。
The text was updated successfully, but these errors were encountered:
No branches or pull requests
设置
builder.callTimeout(1, TimeUnit.SECONDS);
之后不会执行到AbsCallback
里面的onError
问题出在这里:
if (!call.isCanceled()) { // 问题出在这里
当 callTimeout 在 okHttp 里面被触发的时候,IOException 是: java.io.InterruptedIOException: timeout
并且 RealCall.this.isCanceled() 返回 true
所以就没有机会调用到指定的 onError 回调了。
The text was updated successfully, but these errors were encountered: