Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for Issue-229: possibility of simultaneous usage of prod and sandbox #230

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Fix for Issue-229: possibility of simultaneous usage of prod and sand…
…box, switching between them dynamically
  • Loading branch information
lukaszbajorski-filmbooking committed Oct 18, 2024
commit 277dccabdf2012ebfcef73d4a25d86a5ec85a643
4 changes: 3 additions & 1 deletion MangoPay.SDK/Core/ResponseException.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ public ResponseException(string message, int responseStatusCode) : base(message)
try
{
this.ResponseErrorRaw = message;
this.ResponseError = JsonConvert.DeserializeObject<ResponseError>(message);
this.ResponseStatusCode = responseStatusCode;
if (message != null) {
this.ResponseError = JsonConvert.DeserializeObject<ResponseError>(message);
}
}
catch (JsonException)
{
Expand Down
13 changes: 7 additions & 6 deletions MangoPay.SDK/Core/RestTool.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -11,9 +12,9 @@ namespace MangoPay.SDK.Core
{
public class RestSharpDto
{
private static RestSharpDto _instance = null;
private static readonly Dictionary<string, RestSharpDto> _instances = new Dictionary<string, RestSharpDto>();

private static object _lock = new object();
private static readonly object _lock = new object();

private readonly RestClientOptions _options;

Expand All @@ -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];
}
}

Expand Down