From e48b070fa19b4dd4b4033b31caa8719730991129 Mon Sep 17 00:00:00 2001 From: Wenbin Date: Sat, 9 May 2020 21:53:39 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E5=AF=B9=20callTimeout=20?= =?UTF-8?q?=E7=9A=84=E6=94=AF=E6=8C=81=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- okgo/src/main/java/com/lzy/okgo/OkGo.java | 1 + .../java/com/lzy/okgo/cache/policy/BaseCachePolicy.java | 6 ++++++ 2 files changed, 7 insertions(+) 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); + } } } }