From 178e3712d379fe6e451a3ab047797c6b66af4a55 Mon Sep 17 00:00:00 2001 From: gedoor Date: Tue, 4 May 2021 13:18:14 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../main/java/io/legado/app/help/http/OkHttpUtils.kt | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt index 3b15acf5d..b0bcfef18 100644 --- a/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt +++ b/app/src/main/java/io/legado/app/help/http/OkHttpUtils.kt @@ -21,13 +21,14 @@ suspend fun OkHttpClient.newCall( val requestBuilder = Request.Builder() requestBuilder.header(AppConst.UA_NAME, AppConfig.userAgent) requestBuilder.apply(builder) + var response: Response? = null for (i in 0..retry) { - val response = this.newCall(requestBuilder.build()).await() + response = this.newCall(requestBuilder.build()).await() if (response.isSuccessful) { return response.body!! } } - throw IOException("服务器没有响应。") + throw IOException(response?.message ?: "服务器没有响应。") } suspend fun OkHttpClient.newCallStrResponse( @@ -37,13 +38,14 @@ suspend fun OkHttpClient.newCallStrResponse( val requestBuilder = Request.Builder() requestBuilder.header(AppConst.UA_NAME, AppConfig.userAgent) requestBuilder.apply(builder) + var response: Response? = null for (i in 0..retry) { - val response = this.newCall(requestBuilder.build()).await() + response = this.newCall(requestBuilder.build()).await() if (response.isSuccessful) { return StrResponse(response, response.body!!.text()) } } - throw IOException("服务器没有响应。") + throw IOException(response?.message ?: "服务器没有响应。") } suspend fun Call.await(): Response = suspendCancellableCoroutine { block ->