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

edenman

01/28/2021, 7:52 PM
ResponseException
has an
HttpResponse
on it, but it looks like by the time I
catch
that exception, the response has already been consumed. I want to parse the json on the response, what’s the best way to do that?
looks like maybe I need to install my own `HttpResponseValidator`…the default one consumes the response body…but then doesn’t set that string on the
ResponseException
😭
r

Rustam Siniukov

01/28/2021, 8:10 PM
how do you try to read the response body?
exception.response.receive<Type>()
should work
e

edenman

01/28/2021, 8:10 PM
exception.response.content.readEntireUTF8()
the response has already been read by the point i get that exception, so it returns empty string
r

Rustam Siniukov

01/28/2021, 8:12 PM
please use
exception.response.receive<String>()
.
content
can be consumed only once, indeed
e

edenman

01/28/2021, 8:12 PM
i think because
addDefaultResponseValidation
does its own
exceptionResponse.readText()
ah cool, will try that, tx
yeaahhhhh that did it, thanks @Rustam Siniukov!
👍 1
6 Views