diff --git a/lib/http/client.js b/lib/http/client.js index 73896cf9..52ca58d6 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -231,17 +231,17 @@ HTTPClient.prototype._request = async function _request(method, endpoint, json) if (!res.body) throw new Error('Bad response (no body).'); - const network = res.headers['x-bcoin-network']; - - if (network && network !== this.network.type) - throw new Error('Bad response (wrong network).'); - if (res.body.error) throw new Error(res.body.error.message); if (res.statusCode !== 200) throw new Error(`Status code: ${res.statusCode}.`); + const network = res.headers['x-bcoin-network']; + + if (network && network !== this.network.type) + throw new Error('Bad response (wrong network).'); + return res.body; }; diff --git a/lib/http/rpcclient.js b/lib/http/rpcclient.js index c8a498bd..0e44e6ae 100644 --- a/lib/http/rpcclient.js +++ b/lib/http/rpcclient.js @@ -62,9 +62,6 @@ RPCClient.prototype.execute = async function execute(method, params) { if (res.statusCode === 401) throw new RPCError('Unauthorized (bad API key).', -1); - if (res.statusCode !== 200) - throw new Error(`Status code: ${res.statusCode}.`); - if (res.type !== 'json') throw new Error('Bad response (wrong content-type).'); @@ -74,6 +71,9 @@ RPCClient.prototype.execute = async function execute(method, params) { if (res.body.error) throw new RPCError(res.body.error.message, res.body.error.code); + if (res.statusCode !== 200) + throw new Error(`Status code: ${res.statusCode}.`); + return res.body.result; };