[csharp-netcore] HttpClient/Set TimeoutException to inner exception in case of timeout (#13862)

* Changed to TimeoutException

* Handle timeout exceptions as inner exceptions.

* Corrected arguments for compatibility
This commit is contained in:
TORISOUP
2023-02-08 11:28:55 +09:00
committed by GitHub
parent e13a4e143b
commit 7ca0b92944
3 changed files with 27 additions and 0 deletions

View File

@@ -531,6 +531,15 @@ namespace {{packageName}}.Client
return await ToApiResponse<T>(response, responseData, req.RequestUri);
}
catch (OperationCanceledException original)
{
if (timeoutTokenSource != null && timeoutTokenSource.IsCancellationRequested)
{
throw new TaskCanceledException($"[{req.Method}] {req.RequestUri} was timeout.",
new TimeoutException(original.Message, original));
}
throw;
}
finally
{
if (timeoutTokenSource != null)

View File

@@ -533,6 +533,15 @@ namespace {{packageName}}.Client
return await ToApiResponse<T>(response, responseData, req.RequestUri);
}
catch (OperationCanceledException original)
{
if (timeoutTokenSource != null && timeoutTokenSource.IsCancellationRequested)
{
throw new TaskCanceledException($"[{req.Method}] {req.RequestUri} was timeout.",
new TimeoutException(original.Message, original));
}
throw;
}
finally
{
if (timeoutTokenSource != null)

View File

@@ -530,6 +530,15 @@ namespace Org.OpenAPITools.Client
return await ToApiResponse<T>(response, responseData, req.RequestUri);
}
catch (OperationCanceledException original)
{
if (timeoutTokenSource != null && timeoutTokenSource.IsCancellationRequested)
{
throw new TaskCanceledException($"[{req.Method}] {req.RequestUri} was timeout.",
new TimeoutException(original.Message, original));
}
throw;
}
finally
{
if (timeoutTokenSource != null)