Skip to content

Ktorfit error handling #387

@smelfungus

Description

@smelfungus

Please complete the following information:

  • Library Version: 2.0.9

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.

val apiResponse: ApiResponse<Any> = try {
when (result) {
is KtorfitResult.Success ->
ApiResponse.Success(result.response.body(typeData.typeArgs.first().typeInfo))
is KtorfitResult.Failure -> ApiResponse.exception(result.throwable)
}
} catch (e: Throwable) {
ApiResponse.exception(e)
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions