diff --git a/src/Blockcore.Indexer.Core/Client/BitcoinClient.cs b/src/Blockcore.Indexer.Core/Client/BitcoinClient.cs index 6cbd9c0e..60586322 100644 --- a/src/Blockcore.Indexer.Core/Client/BitcoinClient.cs +++ b/src/Blockcore.Indexer.Core/Client/BitcoinClient.cs @@ -581,6 +581,11 @@ private async Task CheckResponseOkAsync(HttpResponseMessage response) JsonRpcResponse ret = JsonConvert.DeserializeObject>(jsonResult); + if (ret?.Error != null) + { + HandleError(jsonResult, response); + } + return ret == null ? default(T) : ret.Result; } } @@ -628,29 +633,21 @@ private T CheckResponseOk(HttpResponseMessage response) { using (var jsonStreamReader = new StreamReader(jsonStream)) { + string jsonResult = jsonStreamReader.ReadToEndAsync().Result; + if (response.StatusCode != HttpStatusCode.OK) { - JsonRpcResponse errRet = null; - string res = jsonStreamReader.ReadToEndAsync().Result; - - try - { - errRet = JsonConvert.DeserializeObject>(res); - } - catch - { - throw CreateException(response, 0, res); - } - - int code = errRet != null && errRet.Error != null ? errRet.Error.Code : 0; - string msg = errRet != null && errRet.Error != null ? errRet.Error.Message : "Error"; - - throw CreateException(response, code, msg); + HandleError(jsonResult, response); } - JsonRpcResponse ret = JsonConvert.DeserializeObject>(jsonStreamReader.ReadToEndAsync().Result); + JsonRpcResponse ret = JsonConvert.DeserializeObject>(jsonResult); + + if (ret?.Error != null) + { + HandleError(jsonResult, response); + } - return ret.Result; + return ret == null ? default(T) : ret.Result; } } }