All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.http4k.connect.RemoteFailure.kt Maven / Gradle / Ivy

There is a newer version: 5.35.2.0
Show newest version
package org.http4k.connect

import dev.forkhandles.result4k.Result
import dev.forkhandles.result4k.recover
import org.http4k.core.Method
import org.http4k.core.Response
import org.http4k.core.Status
import org.http4k.core.Uri

data class RemoteFailure(val method: Method, val uri: Uri, val status: Status, val message: String? = null) {
    fun throwIt(): Nothing = throw Exception(toString())
}

fun  Action.asRemoteFailure(response: Response) =
    with(toRequest()) { RemoteFailure(method, uri, response.status, response.bodyString()) }

fun  Result.orThrow() = recover { it.throwIt() }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy