rpcclient: check body.error first
This commit is contained in:
parent
b40ac6e081
commit
d76ca37d0d
@ -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;
|
||||
};
|
||||
|
||||
|
||||
@ -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