pull/977/head
gedoor 4 years ago
parent 0fb04f1547
commit 178e3712d3
  1. 10
      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 ->

Loading…
Cancel
Save