From 17f471601a9a716453f8740c7c3c2d08747dd571 Mon Sep 17 00:00:00 2001 From: Jens Schulze Date: Tue, 26 Nov 2024 10:36:17 +0100 Subject: [PATCH] refactor errorhandler --- .../commercetools.Base.Client/ErrorHandler.cs | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs b/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs index fc1d43aca90..04ab0e059b2 100644 --- a/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs +++ b/commercetools.Sdk/commercetools.Base.Client/ErrorHandler.cs @@ -7,22 +7,20 @@ namespace commercetools.Base.Client { public class ErrorHandler : DelegatingHandler { - private Func errorResponseBodyMapper; + private readonly Func _errorResponseBodyMapper; - private readonly ExceptionFactory exceptionFactory; - - public ErrorHandler(Func errorResponseBodyMapper) + public ErrorHandler(Func errorResponseBodyMapper) { - this.errorResponseBodyMapper = errorResponseBodyMapper; + this._errorResponseBodyMapper = errorResponseBodyMapper; } protected override async Task 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; }