Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

need safe response converter #389

Closed
yang961226 opened this issue Aug 10, 2023 · 4 comments · Fixed by #450
Closed

need safe response converter #389

yang961226 opened this issue Aug 10, 2023 · 4 comments · Fixed by #450
Assignees
Labels
enhancement New feature or request

Comments

@yang961226
Copy link

Retrofit's Response Converter supports converting the abnormal result into a successful result when an exception occurs during the network request process, but Ktorfit currently can only convert the case where no exception occurs, which makes me have to use try-catch to wrap For the request method, can I add a Converter so that I can continue to convert the result when the request reports an error instead of directly causing the framework to throw an exception

@yang961226 yang961226 added the enhancement New feature or request label Aug 10, 2023
@Foso
Copy link
Owner

Foso commented Aug 10, 2023

Hi, are you looking from something like de.jensklingenberg.ktorfit.Response ?

interface ExampleApi{
  suspend fun getUser(): Response<User>
}

val userResponse = userKtorfit.create<ExampleApi>().getUser()
    
if(userResponse.isSuccessful){
  userResponse.body()
}else{
  userResponse.errorBody()
}

@Ric-AB
Copy link

Ric-AB commented Aug 12, 2023

In addition, when using response converter, I currently can't see any way to handle non-http exceptions from the docs. For example if there's no connectivity, UnresolvedHostException is thrown there's no way to handle such exceptions using response converters.

@yang961226
Copy link
Author

What @Ric-AB said exactly what I wanted to say, UnresolvedHostException unable to handle non-Http exceptions,it just throw the exception and no way to handle it.

@Foso Foso self-assigned this Oct 3, 2023
@Foso
Copy link
Owner

Foso commented Oct 3, 2023

Hi, i understand the need for that feature and will make it work to handle these exception from inside a converter

Foso added a commit that referenced this issue Oct 8, 2023
Foso added a commit that referenced this issue Oct 8, 2023
@Foso Foso linked a pull request Oct 8, 2023 that will close this issue
1 task
Foso added a commit that referenced this issue Oct 8, 2023
Foso added a commit that referenced this issue Oct 8, 2023
Foso added a commit that referenced this issue Oct 8, 2023
@Foso Foso closed this as completed in #450 Oct 8, 2023
Foso added a commit that referenced this issue Oct 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
Status: ✅ Done
Development

Successfully merging a pull request may close this issue.

3 participants