https://kotlinlang.org logo
Title
a

alon shoshani.86

12/27/2021, 7:37 PM
Hi all, We are using kotlin with ktor server side. and We are using
io.ktor.client.HttpClient
To make http calls between microservices and third parties for example: When the http call succeeded the httpResponse maps automatically to my Object, but when there is error in the http call and it failed, I expect the client will throw an exception with the satatus code 40X 50X, and it's not. I need to check manually what is the status code, and decide what to do. Am I using it wrong? Do you have another client to use?
k

Kanu

12/27/2021, 8:43 PM
I'd say it is quite common behavior as getting unusual http code is not always an exceptional situation. So plenty of http clients do the same
l

Lucas Milotich

12/27/2021, 8:45 PM
you need to set the
expectSuccess
property in the client creation : https://ktor.io/docs/response-validation.html#default
a

alon shoshani.86

12/28/2021, 7:12 AM
@Kanu I understand but we want to make our lives easier and use something already done by someone and not implement it again 🙂
@Lucas Milotich thx! I'll try it
🙌 1
I managed to do it by the way! thx!
l

Lucas Milotich

12/29/2021, 8:02 PM
great!