Skip to content
New issue

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

添加对 okHttpClient callTimeout 的支持 #938

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions okgo/src/main/java/com/lzy/okgo/OkGo.java
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ private OkGo() {
builder.readTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
builder.writeTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
builder.connectTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);
builder.callTimeout(OkGo.DEFAULT_MILLISECONDS, TimeUnit.MILLISECONDS);

HttpsUtils.SSLParams sslParams = HttpsUtils.getSslSocketFactory();
builder.sslSocketFactory(sslParams.sSLSocketFactory, sslParams.trustManager);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,12 @@ public void onFailure(okhttp3.Call call, IOException e) {
if (!call.isCanceled()) {
Response<T> error = Response.error(false, call, null, e);
onError(error);
} else {
// 这个 `else` 是为了解决 callTimeout 无法触发 onError 回调
if (e instanceof InterruptedIOException) {
Response<T> error = Response.error(false, call, null, e);
onError(error);
}
}
}
}
Expand Down