@@ -2,6 +2,7 @@ package io.legado.app.help.http.cronet
|
||||
|
||||
import io.legado.app.help.http.okHttpClient
|
||||
import io.legado.app.utils.DebugLog
|
||||
import io.legado.app.utils.rethrowAsIOException
|
||||
import okhttp3.*
|
||||
import okhttp3.EventListener
|
||||
import okhttp3.MediaType.Companion.toMediaTypeOrNull
|
||||
@@ -123,7 +124,7 @@ abstract class AbsCallBack(
|
||||
//UrlResponseInfo可能为null
|
||||
override fun onFailed(request: UrlRequest, info: UrlResponseInfo?, error: CronetException) {
|
||||
DebugLog.i(javaClass.name, error.message.toString())
|
||||
mException = IOException(error.message, error)
|
||||
mException = error.rethrowAsIOException()
|
||||
this.eventListener?.callFailed(mCall, error)
|
||||
responseCallback?.onFailure(mCall, error)
|
||||
}
|
||||
|
||||
@@ -55,9 +55,12 @@ object CronetLoader : CronetEngine.Builder.LibraryLoader() {
|
||||
* 判断Cronet是否安装完成
|
||||
*/
|
||||
fun install(): Boolean {
|
||||
if (cacheInstall) {
|
||||
return true
|
||||
synchronized(this) {
|
||||
if (cacheInstall) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
|
||||
if (AppConfig.isGooglePlay) {
|
||||
return false
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
package io.legado.app.utils
|
||||
|
||||
import java.io.IOException
|
||||
|
||||
val Throwable.msg: String
|
||||
get() {
|
||||
val stackTrace = stackTraceToString()
|
||||
@@ -8,4 +10,10 @@ val Throwable.msg: String
|
||||
stackTrace.isNotEmpty() -> stackTrace
|
||||
else -> lMsg
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun Throwable.rethrowAsIOException(): IOException {
|
||||
val newException = IOException(this.message)
|
||||
newException.initCause(this)
|
||||
throw newException
|
||||
}
|
||||
Reference in New Issue
Block a user