Changed http handler to not throw on non-successful results (#170)
Co-authored-by: Adam Hathcock <adamhathcock@users.noreply.github.com>
This commit is contained in:
@@ -51,39 +51,30 @@ public sealed class SpeckleHttpClientHandler : DelegatingHandler
|
||||
.ConfigureAwait(false);
|
||||
context.TryGetValue("retryCount", out var retryCount);
|
||||
activity?.SetTag("retryCount", retryCount);
|
||||
if (policyResult.FinalException != null)
|
||||
{
|
||||
activity?.RecordException(policyResult.FinalException);
|
||||
activity?.SetStatus(SdkActivityStatusCode.Error);
|
||||
}
|
||||
else
|
||||
{
|
||||
activity?.SetStatus(
|
||||
policyResult.Result.IsSuccessStatusCode ? SdkActivityStatusCode.Ok : SdkActivityStatusCode.Error
|
||||
);
|
||||
}
|
||||
|
||||
if (policyResult.Outcome == OutcomeType.Successful)
|
||||
{
|
||||
activity?.SetStatus(SdkActivityStatusCode.Ok);
|
||||
return policyResult.Result;
|
||||
}
|
||||
|
||||
activity?.SetStatus(SdkActivityStatusCode.Error);
|
||||
if (policyResult.FinalException != null)
|
||||
|
||||
if (policyResult.FinalException is null)
|
||||
{
|
||||
activity?.RecordException(policyResult.FinalException);
|
||||
// Outcome was not successful, but did not terminate with an exception (e.g. repeated 500 responses)
|
||||
return policyResult.FinalHandledResult;
|
||||
}
|
||||
|
||||
activity?.RecordException(policyResult.FinalException);
|
||||
|
||||
// if the policy failed due to a cancellation, AND it was our cancellation token, then don't wrap the exception, and rethrow an new cancellation
|
||||
if (policyResult.FinalException is OperationCanceledException)
|
||||
{
|
||||
cancellationToken.ThrowIfCancellationRequested();
|
||||
}
|
||||
|
||||
throw new HttpRequestException(
|
||||
"Policy Failed: " + policyResult.FinalHandledResult?.StatusCode ?? "Unknown",
|
||||
policyResult.FinalException
|
||||
);
|
||||
throw new HttpRequestException("Policy Failed", policyResult.FinalException);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user