Refit: feature: Exceptions should be exceptional

Created on 21 Feb 2020  路  4Comments  路  Source: reactiveui/refit

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

enhancement up-for-grabs

Most helpful comment

@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.

All 4 comments

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.

I suggest combining it with https://github.com/reactiveui/refit/issues/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.

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

@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.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

jamiehowarth0 picture jamiehowarth0  路  5Comments

omares picture omares  路  6Comments

hiraldesai picture hiraldesai  路  4Comments

martincostello picture martincostello  路  3Comments

AnjaliSahu51 picture AnjaliSahu51  路  4Comments