I'm using nodeJs request-promise library to make call to an endpoint. It works fine for status codes like 200, but whenever server throws 401 (which is a response, not an error), this piece of code returns error and falls into the catch block of calling code.
Is this expected? I want 401 or any other code to be returned as is and don't fall into catch block.
const rp = require('request-promise');
MyService.prototype.getTokenValidity = requestWrapper(function() {
const host = this._config.serverHost;
const url = `${host}/console/api/v1/isTokenValid`;
return rp({
method: 'GET',
url: url,
headers: this._headers,
json: true,
resolveWithFullResponse: true
}).then(function(response) {
console.log(arguments);
console.log(response);
return response;
});
});
via colossal
No comments:
Post a Comment