Throw exception in okhttp coroutine if response isn't successful

This commit is contained in:
arkon 2020-02-03 18:56:24 -05:00
parent 160ebe01d9
commit 09891bb0ad

View File

@ -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)
}