From ccbba6dd38f6f4b26790c7820c090b478bb8248e Mon Sep 17 00:00:00 2001 From: tiagosiebler Date: Wed, 17 Jun 2020 12:05:31 +0100 Subject: [PATCH] approach to fixing #12 --- lib/request.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/lib/request.js b/lib/request.js index 8a431c9..56e0917 100644 --- a/lib/request.js +++ b/lib/request.js @@ -78,11 +78,18 @@ module.exports = class Request { return new Promise((resolve, reject) => { request(options, function callback(error, response, body) { - if(!error && response.statusCode == 200) { - resolve(body); - } else if(error) { - reject(error); + if (error) { + return reject(error); } + if (response.statusCode == 200) { + return resolve(body); + } + return reject({ + code: response.statusCode, + message: response.statusMessage, + body: response.body, + requestOptions: options + }); }); }); }