🥪 Sandwich is an adaptable and lightweight sealed API library designed for handling API responses and exceptions in Kotlin for Retrofit, Ktor, and Kotlin Multiplatform.
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.
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!
Please complete the following information:
Describe the Bug:
It seems that Sandwich's
ApiResponseConverterFactory
is treating allKtorfitResult.Success
responses asApiResponse.Success
. However, this may not always be correct becauseKtorfitResult.Success
can contain HTTP responses with error status codes. Currently, the factory does not take Sandwich'ssuccessCodeRange
into account, which leads to HTTP errors being incorrectly classified as successes. Additionally, it appears that no responses are ever mapped toApiResponse.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