Reputation: 981
Any pointers in the right direction much appreciated, I am use node/express and still a beginner at it, trying to re-use some code from a previous working project but have gotten stuck.
Trying to access an API that would be used for verifying emails but the response is not giving me the statusCode I expect.
var request = require('request');
var ValidEmailApiURL = "(path to api)";
module.exports = {
verifyEmailAPI: function(emailToken) {
return new Promise(function(resolve, reject) {
request({
url: ValidEmailApiURL ,
method: 'PUT'
}, function(err, res, body) {
console.log(res.statusCode);
if (err) reject(err);
if (res.statusCode === 200) {
return resolve(body);
} else if (res.statusCode === 404) {
return reject(body);
//return resolve(body);
}
});
});
}
};
I am expecting res.statusCode to give me 404 but it instead gives me underfined. The API url, through postman returns a response like so:
{ "statusCode": 404, "message": "Resource not found" }
thanks
Upvotes: 1
Views: 1177
Reputation: 1708
If an error occurs, you might not necessarily get a status code back. The err
object might tell you more about what is happening here.
Upvotes: 1