Skip to content

ThrowOnAnyError does not throw #1511

Closed
@trj2000

Description

@trj2000

Expected Behavior

When creating a RestClient, initialized with ThrowOnAnyError = true, I expect an exception to be thrown when a request fails, as per the documentation: Error Handling

Actual Behavior

No exception is thrown.

For sync requests, the exception is caught in ExecuteRequest, for async requests it's caught in GetStyleMethodInternalAsync. In both cases the exception is consumed and a HttpResponse with error info is returned. No exception gets thrown. Instead, the error response is returned, regardless of the value of ThrowOnAnyError.

Steps to Reproduce the Problem

A simple request against a non-existing endpoint shows the problem:

var req = new RestRequest("nonexisting");
var client = new RestClient("http://localhost:12345") { ThrowOnAnyError=true };
Assert.Throws<Exception>(() => client.Execute(req));    // Fails: no exception is thrown

Specifications

  • Version: 106.11.7
  • Platform: Windows x64

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions