瀏覽代碼

Throw exception in okhttp coroutine if response isn't successful

arkon 5 年之前
父節點
當前提交
09891bb0ad
共有 1 個文件被更改,包括 5 次插入0 次删除
  1. 5 0
      app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt

+ 5 - 0
app/src/main/java/eu/kanade/tachiyomi/network/OkHttpExtensions.kt

@@ -52,6 +52,11 @@ suspend fun Call.await(): Response {
     return suspendCancellableCoroutine { continuation ->
         enqueue(object : Callback {
             override fun onResponse(call: Call, response: Response) {
+                if (!response.isSuccessful) {
+                    continuation.resumeWithException(Exception("HTTP error ${response.code}"))
+                    return
+                }
+
                 continuation.resume(response)
             }