-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
When the request is timed out, RepsonseStatus becomes TimedOut, but ErrorMessage becomes “A task was canceled”, which is a bit contradictory.
To Reproduce
Code
using RestSharp;
using var client = new RestClient("http://google.com");
var request = new RestRequest("index.html"){Timeout = TimeSpan.FromMilliseconds(1)};
var response = await client.ExecuteAsync(request);
Console.WriteLine(response.ResponseStatus);
Console.WriteLine(response.ErrorMessage);
- Run the code above
- If needed, use Fiddler or any other tool/method to force the request to time out.
- Observe the status and error message in the console. It should be
TimedOut //<--ResponseStatus
A task was canceled. //<--ErrorMessage
Expected behavior
The ErrorMessage should tell us about the timeout I guess, to be consistent with the status and real situation (no cancellation was requested from user). For example, in the RestSharp 106 the message was "The operation has timed out." or "The request timed-out." depending on where the timeout was set (on the RestClient or RestResponse, respectively). As an alternative the full error message from the inner HttpClient may be used. It looks like this: "The request was canceled due to the configured HttpClient.Timeout of 0,001 seconds elapsing." and also describes the situation in non-confusing way.
Stack trace
No exception.
Desktop (please complete the following information):
- OS: macOS 14.6.1 & Win11
- .NET version net8
- Version 111.4.1
Additional context
none