When using native promises .catch() with error filter, if the function with received body throws an error, the constructor of the error itself throws another error.
TypeError: Cannot set property 'name' of undefined
at StatusCodeError (/home/user/project/node_modules/request-promise-core/lib/errors.js:24:15)
Using this require syntax
const request = require('request-promise-native');
const errors = require('request-promise-native/errors');
consider the following snippet, when the REST API returns status='error':
return request(options)
.then((reply) => {
if (reply.status === 'ok') {
return (reply.data.user.email === user.email);
} else {
throw new Error(reply.message || 'Authentication service error');
}
}).catch(errors.StatusCodeError, err => {
if (err.statusCode === 401) {
console.error('AuthService rejected our authentication settings');
} else throw err;
});
NodeJS: 12.8.0
npm: 6.10.2
When using native promises .catch() with error filter, if the function with received body throws an error, the constructor of the error itself throws another error.
Using this require syntax
consider the following snippet, when the REST API returns status='error':
NodeJS: 12.8.0
npm: 6.10.2