https://kotlinlang.org logo
Title
j

Jan

12/27/2021, 2:29 PM
Can I somehow get away from these exceptions? I'm handling these myself
a

Aleksei Tirman [JB]

12/27/2021, 2:36 PM
You can disable default response validation by setting
expectSuccess
property to `false`https://ktor.io/docs/response-validation.html#default
j

Jan

12/27/2021, 2:41 PM
thanks 😄
But then this doesn't call?:
HttpResponseValidator {
            handleResponseException {
                val clientException = it as? ClientRequestException ?: return@handleResponseException
                errorHandler.handle(clientException)
            }
        }
in the http client
a

Aleksei Tirman [JB]

12/27/2021, 2:47 PM
What do you mean?
Could you please describe your problem?
j

Jan

12/27/2021, 2:50 PM
when I set the expectSuccess to false, the response validator thing doesnt get called. Thats my full builder:
val http = HttpClient {
        config.httpClientConfig(this)
        defaultRequest {
            header("Authorization", "Bot ${config.token}")
            header("User-Agent", "<http://Discord.KM|Discord.KM> (\$<https://github.com/jan-tennert/Discord.KM>, $0.3)")
        }

        HttpResponseValidator {
            handleResponseException {
                val clientException = it as? ClientRequestException ?: return@handleResponseException
                errorHandler.handle(clientException)
            }
        }

        expectSuccess = false
    }
a

Aleksei Tirman [JB]

12/28/2021, 9:27 AM
It gets called if any exceptions are thrown. You can use
validateResponse
inside
HttpResponseValidator
to validate a response.
So you can disable default response validation and do it by yourself.