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

Azur Haljeta

02/02/2021, 3:11 PM
HttpResponseValidator{}
doesn't work anymore in 1.5.0, why? It doesn't get called at all https://ktor.io/docs/response-validation.html
there is already an opened issue: https://youtrack.jetbrains.com/issue/KTOR-1616
but it still doesn't work
r

Rustam Siniukov

02/02/2021, 3:30 PM
1. make sure that you don’t overwrite
expectSuccess
in client config with
false
2. custom validations happens AFTER default validation. so if you want to handle non 200 status, your validator will not be called, because default one already threw exception
the issue that you send is closed and you can read comments for more details
a

Azur Haljeta

02/02/2021, 3:32 PM
but I don't want anything by default, I already have code which handles this but this isn't an option anymore?
meaning I don't need default validation
so there is no way to avoid default validation?
what's the point of
validateResponse
if it doesn't get called
yeah there are comments in the ticket but still a breaking change
r

Rustam Siniukov

02/02/2021, 3:43 PM
there are three use cases for custom validation: 1. you want more strict validation of 200 responses - it works with default validation 2. you want different handling of non 200 responses - you can use
handleResponseException
with minor code change 3. you want less strict validation - this is not supported, because it’s how feature is meant to be used. Previous behaviour was wrong
a

Azur Haljeta

02/02/2021, 3:55 PM
ok thanks when you say
Previous behaviour was wrong
you mean on how ktor handled validation before
1.5.0
r

Rustam Siniukov

02/02/2021, 4:00 PM
yes, that’s correct. if you will write your use case, I can help you with the migration
a

Azur Haljeta

02/02/2021, 4:06 PM
thanks, already done basically
HttpResponse
is now wrapped within
ClientRequestException
and that's what my logic relied on
👍 1
4 Views