skydoves / sandwich

🥪 Sandwich is an adaptable and lightweight sealed API library designed for handling API responses and exceptions in Kotlin for Retrofit, Ktor, and Kotlin Multiplatform.
https://skydoves.github.io/sandwich/
Apache License 2.0
1.57k stars 101 forks source link

Ktorfit error handling #387

Closed smelfungus closed 1 month ago

smelfungus commented 1 month ago

Please complete the following information:

Describe the Bug:

It seems that Sandwich's ApiResponseConverterFactory is treating all KtorfitResult.Success responses as ApiResponse.Success. However, this may not always be correct because KtorfitResult.Success can contain HTTP responses with error status codes. Currently, the factory does not take Sandwich's successCodeRange into account, which leads to HTTP errors being incorrectly classified as successes. Additionally, it appears that no responses are ever mapped to ApiResponse.Error, even when the HTTP status code would suggest otherwise.

https://github.com/skydoves/sandwich/blob/308494971fa873a24ed4533166d29af529a2f59a/sandwich-ktorfit/src/commonMain/kotlin/com/skydoves/sandwich/ktorfit/ApiResponseConverterFactory.kt#L50-L59

smelfungus commented 1 month ago

I’ve just submitted my take on improving the handling in a pull request #388. Would love for you to check it out when you have a moment and share your thoughts. Thanks a ton!