Skip to content

Option to distinguish actual exceptions from "Request failed with status code" #2302

@oliversaggau

Description

@oliversaggau

Overview:

We are using IRestClient.Execute[Async](request) to do our own error handling. Unfortunately response.ErrorException is not only set when an actual exception happened during the request, but also simply because response.IsSuccessStatusCode was false and unfortunately that case (also) simply uses a System.Net.Htttp.HttpRequestException for doing so. The only way for us to distinguish an actual (HttpRequest-) exception from this one, is by doing something like exception.Message.StartsWith("Request failed with status code") which feels not good.

Use case:

As I said, we want to do our own StatusCode error handling, so I would actually want response.ErrorException to be null when there was no actual exception.

Solution?

I understand that such a change might break existing code. So I would suggest to add an option to RestClientOptions where the user can decide whether response.IsSuccessStatusCode should populate response.ErrorException or not, and that option is than on by default to not change the existing behavior.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions