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 ->