From 277dccabdf2012ebfcef73d4a25d86a5ec85a643 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C5=81ukasz=20Bajorski?= Date: Fri, 18 Oct 2024 11:24:09 +0200 Subject: [PATCH] Fix for Issue-229: possibility of simultaneous usage of prod and sandbox, switching between them dynamically --- MangoPay.SDK/Core/ResponseException.cs | 4 +++- MangoPay.SDK/Core/RestTool.cs | 13 +++++++------ 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/MangoPay.SDK/Core/ResponseException.cs b/MangoPay.SDK/Core/ResponseException.cs index b0d4305f..d66ef941 100644 --- a/MangoPay.SDK/Core/ResponseException.cs +++ b/MangoPay.SDK/Core/ResponseException.cs @@ -17,8 +17,10 @@ public ResponseException(string message, int responseStatusCode) : base(message) try { this.ResponseErrorRaw = message; - this.ResponseError = JsonConvert.DeserializeObject(message); this.ResponseStatusCode = responseStatusCode; + if (message != null) { + this.ResponseError = JsonConvert.DeserializeObject(message); + } } catch (JsonException) { diff --git a/MangoPay.SDK/Core/RestTool.cs b/MangoPay.SDK/Core/RestTool.cs index 975016e1..bc2674f4 100644 --- a/MangoPay.SDK/Core/RestTool.cs +++ b/MangoPay.SDK/Core/RestTool.cs @@ -2,6 +2,7 @@ using MangoPay.SDK.Entities; using RestSharp; using System; +using System.Collections; using System.Collections.Generic; using System.Linq; using System.Net; @@ -11,9 +12,9 @@ namespace MangoPay.SDK.Core { public class RestSharpDto { - private static RestSharpDto _instance = null; + private static readonly Dictionary _instances = new Dictionary(); - private static object _lock = new object(); + private static readonly object _lock = new object(); private readonly RestClientOptions _options; @@ -33,18 +34,18 @@ private RestSharpDto(string url, int timeout) public static RestSharpDto GetInstance(string url, int timeout) { - if (_instance == null) + if (!_instances.ContainsKey(url)) { lock (_lock) // now I can claim some form of thread safety... { - if (_instance == null) + if (!_instances.ContainsKey(url)) { - _instance = new RestSharpDto(url, timeout); + _instances[url] = new RestSharpDto(url, timeout); } } } - return _instance; + return _instances[url]; } }