Merge pull request #329 from nodar-chkuaselidze/fix/http-client
Fix bcoin.http.Client errors
This commit is contained in:
commit
8c091f6e08
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
|
||||
Loading…
Reference in New Issue
Block a user