https://kotlinlang.org logo
#ktor
Title
# ktor
o

Orhan Tozan

06/23/2020, 3:50 PM
Why does the Ktor client not allow me to get the response body of a non-200 response? 😕
j

Jurriaan Mous

06/23/2020, 4:12 PM
I do this:
Copy code
try {
        call()
    } catch (e: ResponseException) {
        val status = e.response.status
        val body = e.response.readText()
call() is a function reference to a normal ktor call
o

Orhan Tozan

06/23/2020, 4:17 PM
Hmm, I think I already tried that. Besides that, is it by design that the exception of a request doesnt get thrown until you call readText()?
r

r4zzz4k

06/23/2020, 5:17 PM
There is a way to disable exceptions for non-2xx codes if that's what you are aiming for: https://ktor.io/clients/http-client/features/response-validation.html#expect-success
2