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

HttpRequestException handling #7

Closed
michaelfoster9 opened this issue Jul 22, 2023 · 2 comments · Fixed by #9
Closed

HttpRequestException handling #7

michaelfoster9 opened this issue Jul 22, 2023 · 2 comments · Fixed by #9

Comments

@michaelfoster9
Copy link

Hello, I have been using this library and I love it. I have implemented some error handlers using your OnFailure methods. That works great for failure responses returned from the server. What is the strategy for handling HttpRequestExceptions which would get thrown, for example, if the users internet connection was down.

It would be nice to be able to hande that within this framework. Please let me know if there is a way to do that, or if that is a possible future feature.

@scottoffen
Copy link
Owner

scottoffen commented Jan 9, 2024

Yep, this can be done.

  • I've added Action<HttpRequestException> HttpRequestExceptionHandler to the HttpRequestBuilder class.

  • I updated the send method to catch the exception and, if an action has been defined, it will pass that exception to the action and then return null. If that action hasn't been defined, it will rethrow the exception. You can always rethrow the exception in the handler if you want to.

  • I added the extension method OnHttpRequestException that will allow the action to be defined using the same fluent syntax that is the core of this library.

All this will be in the v3.0 release.

scottoffen added a commit that referenced this issue Jan 9, 2024
@scottoffen scottoffen mentioned this issue Jan 9, 2024
@scottoffen
Copy link
Owner

This has been deprecated in version 4 in favor of using a more comprehensive tool such as Polly.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants