Foso / Ktorfit

HTTP client generator / KSP plugin for Kotlin Multiplatform (Android, iOS, Js, Jvm, Native) using KSP and Ktor clients inspired by Retrofit https://foso.github.io/Ktorfit
https://foso.github.io/Ktorfit
Apache License 2.0
1.53k stars 39 forks source link

Ktorfit cant handle validation exceptions #646

Open naixx opened 2 weeks ago

naixx commented 2 weeks ago

Ktorfit version

2.0.0

What happened and how can we reproduce this issue?

Add custom validation to ktor

HttpResponseValidator {
            validateResponse {
                 throw MyHttpException()
            }
}

This exception is not propagated to coroutine suspension function.

try{
   myCoroutine()
catch(e: MyHttpException)

But if you throw any subtype of ResponseException, you will be able to catch it.

What did you expect to happen?

Any exception is propagated to coroutine

Is there anything else we need to know about?

No response

Foso commented 2 weeks ago

It just tried to reproduce it, the exception is propagated to the catch block and then to the exceptionhandler https://github.com/Foso/Ktorfit/blob/237e2133f12935377626a7c6fba50980efc982de/example/AndroidOnlyExample/app/src/main/java/de/jensklingenberg/androidonlyexample/MainActivity.kt#L79

naixx commented 2 weeks ago

I suspect, it is not catched in catch as iI would expect, but in handler as you've mentioned