From b40ac6e08168486979fd839d87c1e328105dfed2 Mon Sep 17 00:00:00 2001 From: Node Date: Thu, 5 Oct 2017 18:52:14 +0400 Subject: [PATCH] http-client: fix returned errors --- lib/http/client.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/http/client.js b/lib/http/client.js index b9e1ac2a..73896cf9 100644 --- a/lib/http/client.js +++ b/lib/http/client.js @@ -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; };