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

ThrowOnAnyError does not throw #1511

Closed
trj2000 opened this issue Oct 5, 2020 · 5 comments · Fixed by #1515
Closed

ThrowOnAnyError does not throw #1511

trj2000 opened this issue Oct 5, 2020 · 5 comments · Fixed by #1515

Comments

@trj2000
Copy link

trj2000 commented Oct 5, 2020

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
@jbutlerAG
Copy link

@alexeyzimarev - Any estimate on when this fix will be published to the NuGet feed? We're using 106.11.7 and this is still not throwing the error. I also tried the 106.11.8-alpha.0.14 package, but that did not seem to work either.

@qz8
Copy link

qz8 commented Aug 18, 2021

@FrediKats @alexeyzimarev FYI, this is still happening in 106.12.0.

@Larsjep
Copy link

Larsjep commented Jan 11, 2022

@FrediKats @alexeyzimarev This still seems to be a problem in 107.0.2
This basically makes .GetAsync() and .PostAsync() useless 😢

@alexeyzimarev
Copy link
Member

alexeyzimarev commented Jan 11, 2022

@Larsjep I think it's a different issue. And I see why it happens.
#1692

@Larsjep
Copy link

Larsjep commented Jan 11, 2022

Thanks 😀, that was quick 👍
It seems to work now in version 107.0.3.

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.

5 participants