Merge pull request #1 from tiagosiebler/rest/exceptions
REST promise should reject if HTTP status error is seen
This commit is contained in:
@@ -78,11 +78,18 @@ module.exports = class Request {
|
|||||||
|
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
request(options, function callback(error, response, body) {
|
request(options, function callback(error, response, body) {
|
||||||
if(!error && response.statusCode == 200) {
|
if (error) {
|
||||||
resolve(body);
|
return reject(error);
|
||||||
} else if(error) {
|
|
||||||
reject(error);
|
|
||||||
}
|
}
|
||||||
|
if (response.statusCode == 200) {
|
||||||
|
return resolve(body);
|
||||||
|
}
|
||||||
|
return reject({
|
||||||
|
code: response.statusCode,
|
||||||
|
message: response.statusMessage,
|
||||||
|
body: response.body,
|
||||||
|
requestOptions: options
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user