Open
Description
The documentation at https://restsharp.dev/docs/advanced/error-handling/ says that:
ThrowOnAnyError = true
will cause RestSharp to throw exceptions
on any request failure, including when using methods like:...
However, this is not true in practice. The method does not throw on 404/500 status codes.
To Reproduce
`using System;
using System.Threading.Tasks;
using RestSharp;
class Program
{
static async Task Main(string[] args)
{
var options = new RestClientOptions("https://httpstat.us")
{
ThrowOnAnyError = true
};
var client = new RestClient(options);
var request = new RestRequest("/404");
try
{
// From documentation: "π will throw if the request fails"
var response = await client.ExecuteGetAsync<ResponseModel>(request);
Console.WriteLine("β NO EXCEPTION WAS THROWN");
Console.WriteLine($"Status: {(int)response.StatusCode}");
Console.WriteLine($"IsSuccessful: {response.IsSuccessful}");
Console.WriteLine($"Data is null: {response.Data == null}");
}
catch (HttpRequestException ex)
{
Console.WriteLine("HttpRequestException was thrown!");
Console.WriteLine(ex.Message);
}
}
public class ResponseModel
{
public string? Message { get; set; }
}
}
`
Expected behavior
Exeption should be thrown
Stack trace
β NO EXCEPTION WAS THROWN Status: 404 IsSuccessful: False Data is null: False
Desktop:
- OS: [Windows 11 PRO]
- .NET version [e.g. .NET 8]
- Version [e.g. 112.1.0]