From c7b852e282622f2a49a44ce8a6c43d97bfa8516a Mon Sep 17 00:00:00 2001 From: sonvister Date: Wed, 28 Nov 2018 11:05:22 -0500 Subject: [PATCH] Improve WAPI error message handling For #108. --- src/Binance/Api/BinanceApi.cs | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) diff --git a/src/Binance/Api/BinanceApi.cs b/src/Binance/Api/BinanceApi.cs index 5e15556a..8692382c 100644 --- a/src/Binance/Api/BinanceApi.cs +++ b/src/Binance/Api/BinanceApi.cs @@ -923,19 +923,26 @@ private BinanceApiException NewBinanceWApiException(string methodName, string js var error = jObject["msg"].Value(); - 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() ?? 0; - errorMessage = jError["msg"]?.Value(); + errorCode = jError["code"]?.Value() ?? 0; + errorMessage = jError["msg"]?.Value(); + } + 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; } }