From 4c6d03af77492d37f1ff777ecb745ee9f4a02e56 Mon Sep 17 00:00:00 2001 From: Xavier Poinas Date: Wed, 23 Aug 2023 12:17:47 +0300 Subject: [PATCH 1/2] Removed unused variable and made all test conditions uniform using restResponse.StatusCode --- MangoPay.SDK/Core/RestTool.cs | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/MangoPay.SDK/Core/RestTool.cs b/MangoPay.SDK/Core/RestTool.cs index ca9da30..c6a23ab 100644 --- a/MangoPay.SDK/Core/RestTool.cs +++ b/MangoPay.SDK/Core/RestTool.cs @@ -72,9 +72,6 @@ internal class RestTool // key-value collection pass to the request private Dictionary _requestData; - // code get from response - private int _responseCode; - // pagination object private Pagination _pagination; @@ -260,8 +257,6 @@ private async Task DoRequestAsync(string urlMethod, T entity = default, var restResponse = await _dto.Client.ExecuteAsync(restRequest); var responseObject = restResponse.Data; - this._responseCode = (int)restResponse.StatusCode; - if (restResponse.StatusCode == HttpStatusCode.OK || restResponse.StatusCode == HttpStatusCode.NoContent) { _log.Debug("Response OK: " + restResponse.Content); @@ -271,7 +266,7 @@ private async Task DoRequestAsync(string urlMethod, T entity = default, _log.Debug("Response ERROR: " + restResponse.Content); } - if (this._responseCode == 200) + if (restResponse.StatusCode == HttpStatusCode.OK) { _log.Debug("Response object: " + responseObject.ToString()); } @@ -348,8 +343,6 @@ private async Task> DoRequestListAsync(string urlMethod, Dic responseObject = new ListPaginated(restResponse.Data); - this._responseCode = (int)restResponse.StatusCode; - if (restResponse.StatusCode == HttpStatusCode.OK || restResponse.StatusCode == HttpStatusCode.NoContent) { _log.Debug("Response OK: " + restResponse.Content); @@ -359,7 +352,7 @@ private async Task> DoRequestListAsync(string urlMethod, Dic _log.Debug("Response ERROR: " + restResponse.Content); } - if (this._responseCode == 200) + if (restResponse.StatusCode == HttpStatusCode.OK) { responseObject = this.ReadResponseHeaders(restResponse, responseObject); From 67bec4bdc57db1647ebb8c772f54c53689e8e613 Mon Sep 17 00:00:00 2001 From: Xavier Poinas Date: Wed, 23 Aug 2023 12:18:21 +0300 Subject: [PATCH 2/2] Include the HTTP status code in the error logs --- MangoPay.SDK/Core/RestTool.cs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/MangoPay.SDK/Core/RestTool.cs b/MangoPay.SDK/Core/RestTool.cs index c6a23ab..5394709 100644 --- a/MangoPay.SDK/Core/RestTool.cs +++ b/MangoPay.SDK/Core/RestTool.cs @@ -263,7 +263,7 @@ private async Task DoRequestAsync(string urlMethod, T entity = default, } else { - _log.Debug("Response ERROR: " + restResponse.Content); + _log.Debug($"Response ERROR ({(int)restResponse.StatusCode}): " + restResponse.Content); } if (restResponse.StatusCode == HttpStatusCode.OK) @@ -349,7 +349,7 @@ private async Task> DoRequestListAsync(string urlMethod, Dic } else { - _log.Debug("Response ERROR: " + restResponse.Content); + _log.Debug($"Response ERROR ({(int)restResponse.StatusCode}): " + restResponse.Content); } if (restResponse.StatusCode == HttpStatusCode.OK)