Merge pull request #329 from nodar-chkuaselidze/fix/http-client

Fix bcoin.http.Client errors
This commit is contained in:
Christopher Jeffrey (JJ) 2017-10-18 13:11:49 -07:00 committed by GitHub
commit 8c091f6e08
2 changed files with 9 additions and 9 deletions

View File

@ -225,23 +225,23 @@ HTTPClient.prototype._request = async function _request(method, endpoint, json)
if (res.statusCode === 401)
throw new Error('Unauthorized (bad API key).');
if (res.statusCode !== 200)
throw new Error(`Status code: ${res.statusCode}.`);
if (res.type !== 'json')
throw new Error('Bad response (wrong content-type).');
if (!res.body)
throw new Error('Bad response (no body).');
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).');
if (res.body.error)
throw new Error(res.body.error.message);
return res.body;
};

View File

@ -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;
};