diff --git a/MangoPay.SDK/Core/ResponseException.cs b/MangoPay.SDK/Core/ResponseException.cs index b0d4305..d66ef94 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 975016e..bc2674f 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]; } }