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

Pallaw Pathak

11/30/2023, 8:22 AM
Hello Guys, I was using
2.0.0-beta-1
version of Ktor in my KMP project. In this version ktor was throwing an exception whenever server returns
400
. But in latest version of ktor I am not able to get any exception thrown from ktor. Can anyone please help me with this issue? CC @Suresh Maidaragi
p

p-schneider

11/30/2023, 8:23 AM
(I'm assuming you meant
3.0.0-beta-1
or are you actually referring to the 2 year old beta release?)
p

Pallaw Pathak

11/30/2023, 8:31 AM
I previously used version
2.0.0-beta-1
of ktor. Recently, I upgraded to version
2.3.4
and since then, I am facing the issue that I described in my earlier message.
h

Helio

11/30/2023, 8:32 AM
expecteSuccess=true
? Could you be missing this on your client engine?
p

p-schneider

11/30/2023, 8:32 AM
ah, ok. So what does ktor do instead now? (assuming you're using it as client)
h

Helio

11/30/2023, 8:32 AM
Copy code
/**
     * Terminates [HttpClient.receivePipeline] if the status code is not successful (>=300).
     * Learn more from [Response validation](<https://ktor.io/docs/response-validation.html>).
     */
    public var expectSuccess: Boolean = false
p

Pallaw Pathak

11/30/2023, 8:34 AM
Yes, I am using it in my KMM project. With compose multiplatform. So in previous version if we call any API and server sends 400 status code then ktor was immedietly throwing some ResponseError and I was able to catch it. But now it doesn't throw any error in case of 400.
p

p-schneider

11/30/2023, 8:35 AM
(And you may as well upgrade to version 2.3.6 - more bugfixes)
The Response Validator mentioned by Helio should work.
😃 1
p

Pallaw Pathak

11/30/2023, 8:38 AM
Thanks @Helio and @p-schneider I'll try this and let you know how it goes.
👍 1
👍🏽 1
s

Suresh Maidaragi

11/30/2023, 11:33 AM
Thank you @Helio @p-schneider it worked
👍 1
👍🏽 1
2 Views