Skip to content

Commit 3582f73

Browse files
Use descriptive error message for timed out requests (#2356)
When a request times out, ErrorMessage was set to the TaskCanceledException message ("A task was canceled.") which contradicts ResponseStatus.TimedOut. Now ErrorMessage says "The request timed out." for timeout scenarios, keeping all three state properties (ResponseStatus, ErrorMessage, ErrorException) consistent. ErrorException still holds the original TaskCanceledException. Fixes #2257 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent acdf9af commit 3582f73

1 file changed

Lines changed: 4 additions & 2 deletions

File tree

src/RestSharp/RestClient.Async.cs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,11 +61,13 @@ public async Task<RestResponse> ExecuteAsync(RestRequest request, CancellationTo
6161
}
6262

6363
static RestResponse GetErrorResponse(RestRequest request, Exception exception, CancellationToken timeoutToken) {
64+
var timedOut = exception is OperationCanceledException && TimedOut();
65+
6466
var response = new RestResponse(request) {
6567
ResponseStatus = exception is OperationCanceledException
66-
? TimedOut() ? ResponseStatus.TimedOut : ResponseStatus.Aborted
68+
? timedOut ? ResponseStatus.TimedOut : ResponseStatus.Aborted
6769
: ResponseStatus.Error,
68-
ErrorMessage = exception.GetBaseException().Message,
70+
ErrorMessage = timedOut ? "The request timed out." : exception.GetBaseException().Message,
6971
ErrorException = exception
7072
};
7173

0 commit comments

Comments
 (0)