Skip to content

Commit

Permalink
refactor errorhandler
Browse files Browse the repository at this point in the history
  • Loading branch information
jenschude committed Nov 26, 2024
1 parent ab1c08e commit 17f4716
Showing 1 changed file with 5 additions and 7 deletions.
12 changes: 5 additions & 7 deletions commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,22 +7,20 @@ namespace commercetools.Base.Client
{
public class ErrorHandler : DelegatingHandler
{
private Func<HttpResponseMessage, Object> errorResponseBodyMapper;
private readonly Func<HttpResponseMessage, object> _errorResponseBodyMapper;

private readonly ExceptionFactory exceptionFactory;

public ErrorHandler(Func<HttpResponseMessage, Object> errorResponseBodyMapper)
public ErrorHandler(Func<HttpResponseMessage, object> errorResponseBodyMapper)
{
this.errorResponseBodyMapper = errorResponseBodyMapper;
this._errorResponseBodyMapper = errorResponseBodyMapper;
}

protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
{
var response = await base.SendAsync(request, cancellationToken).ConfigureAwait(false);

if (response != null && !response.IsSuccessStatusCode)
if (response is { IsSuccessStatusCode: false })
{
var exception = ExceptionFactory.Create(request, response, errorResponseBodyMapper);
var exception = ExceptionFactory.Create(request, response, _errorResponseBodyMapper);
throw exception;
}

Expand Down

0 comments on commit 17f4716

Please sign in to comment.