Is there a simple way to accept both success (2xx)...
# ktor
l
Is there a simple way to accept both success (2xx) and redirects (3xx) in
HttpClient
, but throw on 4xx and 5xx?
expectSuccess
throws on redirects (3xx) as well.
a
You can add your custom response validator. Here is an example:
Copy code
val client = HttpClient(CIO) {
    HttpResponseValidator {
        validateResponse { response ->
            if (response.status.value >= 400) {
                throw RuntimeException("Invalid response with status ${response.status}")
            }
        }
    }

}

client.get("<http://httpbin.org/status/404>")
l
Thank you very much!