http-client: fix returned errors

This commit is contained in:
Node 2017-10-05 18:52:14 +04:00
parent ca4e938a75
commit b40ac6e081
No known key found for this signature in database
GPG Key ID: 8E1B4DC29040BD90

View File

@ -225,9 +225,6 @@ 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).');
@ -242,6 +239,9 @@ HTTPClient.prototype._request = async function _request(method, endpoint, json)
if (res.body.error)
throw new Error(res.body.error.message);
if (res.statusCode !== 200)
throw new Error(`Status code: ${res.statusCode}.`);
return res.body;
};