diff --git a/okgo/src/main/java/com/lzy/okgo/OkGo.java b/okgo/src/main/java/com/lzy/okgo/OkGo.java index 6e58d81e..a756bc19 100644 --- a/okgo/src/main/java/com/lzy/okgo/OkGo.java +++ b/okgo/src/main/java/com/lzy/okgo/OkGo.java @@ -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); diff --git a/okgo/src/main/java/com/lzy/okgo/cache/policy/BaseCachePolicy.java b/okgo/src/main/java/com/lzy/okgo/cache/policy/BaseCachePolicy.java index f43aad35..850cb2c1 100644 --- a/okgo/src/main/java/com/lzy/okgo/cache/policy/BaseCachePolicy.java +++ b/okgo/src/main/java/com/lzy/okgo/cache/policy/BaseCachePolicy.java @@ -142,6 +142,12 @@ public void onFailure(okhttp3.Call call, IOException e) { if (!call.isCanceled()) { Response error = Response.error(false, call, null, e); onError(error); + } else { + // 这个 `else` 是为了解决 callTimeout 无法触发 onError 回调 + if (e instanceof InterruptedIOException) { + Response error = Response.error(false, call, null, e); + onError(error); + } } } }