Make OkHttp coroutine calls always throw exceptions on errors

This commit is contained in:
arkon
2020-12-24 15:36:57 -05:00
parent c0cef58e39
commit 1268caf3e0
2 changed files with 9 additions and 9 deletions
@@ -52,12 +52,12 @@ fun Call.asObservable(): Observable<Response> {
}
// Based on https://github.com/gildor/kotlin-coroutines-okhttp
suspend fun Call.await(assertSuccess: Boolean = false): Response {
suspend fun Call.await(): Response {
return suspendCancellableCoroutine { continuation ->
enqueue(
object : Callback {
override fun onResponse(call: Call, response: Response) {
if (assertSuccess && !response.isSuccessful) {
if (!response.isSuccessful) {
continuation.resumeWithException(Exception("HTTP error ${response.code}"))
return
}