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

feature: Exceptions should be exceptional #844

Closed
jstafford5380 opened this issue Feb 21, 2020 · 5 comments · Fixed by #900
Closed

feature: Exceptions should be exceptional #844

jstafford5380 opened this issue Feb 21, 2020 · 5 comments · Fixed by #900

Comments

@jstafford5380
Copy link

jstafford5380 commented Feb 21, 2020

Is your feature request related to a problem? Please describe.

When error codes are encountered, Refit throws. While I could catch this and handle it, the cost of the throw has already been incurred.

Describe the solution you'd like

Provide a means to handle the response without the exception being thrown. This could also open a door for project that would like to handle different codes in different ways.

Describe alternatives you've considered

Describe suggestions on how to achieve the feature

Creating an extensible response pipeline could do it. If I could insert a handler that allows me to handle the response and short-circuit the exception, that should suffice. Following a similar pattern as ASP's exception filter pipeline would feel natural, I think.

Additional context

@clairernovotny
Copy link
Member

This could work but we'd need to have a settings configuration to control the new behavior to maintain backwards compatibility.

Open to ideas on how to architect and implement this.

@Dreamescaper
Copy link
Contributor

Dreamescaper commented Mar 22, 2020

I suggest combining it with #272 .
Add something like that to RefitSettings:
Func<HttpResponse, Exception> ExceptionFactory {get; set;}
(with default behavior provided)
And therefore throw only if this Func returns non-null result.

@StephenCleary
Copy link

Refit can wrap HttpClient, which already has a handling pipeline. Would that suit your needs?

@Dreamescaper
Copy link
Contributor

@StephenCleary
You can throw custom exceptions from your HttpClientHandler, if you need, but currently there is no way to disable Refit exceptions for non-2** responses.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 15, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants