Skip to content

Commit

Permalink
Improve WAPI error message handling
Browse files Browse the repository at this point in the history
For #108.
  • Loading branch information
sonvister committed Nov 28, 2018
1 parent a296e58 commit c7b852e
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions src/Binance/Api/BinanceApi.cs
Original file line number Diff line number Diff line change
Expand Up @@ -923,19 +923,26 @@ private BinanceApiException NewBinanceWApiException(string methodName, string js

var error = jObject["msg"].Value<string>();

if (!string.IsNullOrWhiteSpace(error) && error.IsJsonObject())
if (!string.IsNullOrWhiteSpace(error))
{
try // to parse server error response.
if (error.IsJsonObject())
{
var jError = JObject.Parse(error);
try // to parse server error response.
{
var jError = JObject.Parse(error);

errorCode = jError["code"]?.Value<int>() ?? 0;
errorMessage = jError["msg"]?.Value<string>();
errorCode = jError["code"]?.Value<int>() ?? 0;
errorMessage = jError["msg"]?.Value<string>();
}
catch (Exception e)
{
_logger?.LogError(e, $"{nameof(BinanceApi)}.{methodName} failed to parse server error response: \"{error}\"");
throw;
}
}
catch (Exception e)
else
{
_logger?.LogError(e, $"{nameof(BinanceApi)}.{methodName} failed to parse server error response: \"{error}\"");
throw;
errorMessage = error;
}
}

Expand Down

0 comments on commit c7b852e

Please sign in to comment.