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

Dominic Michel

07/08/2020, 6:43 AM
Hey. I'm using the ktor http client and i'm wondering if it can be configured to not throw an exception if the request fails with status 40x. I know about
Copy code
HttpClient {
  expectSuccess = false
}
but if set, the exception just changes from
ClientRequestException
to
IllegalStateException
Can the throwing of exceptions somehow be prevented completely or do i have to resort to a try/catch block?
a

arjun

07/08/2020, 8:58 AM
i havent found a way either. catching the
ClientRequestException
and checking the response statuscode and then parsing the content to get the error body
g

gotoOla

07/08/2020, 7:24 PM
We are doing this by requesting HttpResponse as the type, then we make sure the response is in 200 range and parse the content
Although we are not using content negotiation, we are doing serialization on our own
3 Views