ioki-mobility / kmp-passenger-api

Kotlin Multiplatform ioki Passenger API
MIT License
1 stars 1 forks source link

Api error interceptor could not parse some failed responses where there is no api error body #21

Closed vhontar closed 2 months ago

vhontar commented 2 months ago

@StefMa Thank you for the question!

No, we are still interested in even empty body, because sometimes we need only status code from API. Unfortunately it crashes in parsing if we try to parse empty ApiErrorBody and it just stops the execution. Interceptors wouldn’t get anything.

But we still need status code for some interceptors only.

It was a bug for some interceptors for me in the application, that we don’t receive any interceptions if this body was empty.

Does it make sense? :)

StefMa commented 2 months ago

Thanks for the explanation! You say the app crashes, is that really the case? Because we had everything wrapped here in a try catch? Or was the problem that we don't reach the interceptors?

I also don't like thst we construct an empty ErrorBody. In higher level modules we might think that backend sends us an empty body. Would it make sense to try to parse a nullable ErrorBody instead? And put a null ErrorBody to the interceptors? Would this make more sense? 🤔

vlh-ioki commented 2 months ago

No, it doesn't crash because of the try/catch, but parser itself crashes. Because there is empty body or null body sent by backend.

I'd assume that .body<ApiBodyError?> will work here 🤔

Screenshot 2024-09-13 at 13 01 14

vlh-ioki commented 2 months ago

We need unit tests here: https://github.com/ioki-mobility/kmp-passenger-api/issues/22