I need to validate the 401 which is an authorization error, but need to display an alert, this is my code but I don't know how to send this to the front.
}).on('end', () => {
console.log('response.statusCode ', response.statusCode );
if (response.statusCode < 200 || response.statusCode > 299) {
console.log('error section');
error = new Error('Request Failed.' + `Status Code: ${response.statusCode}`)
console.log('error->', error);
res.send(error);
}else{
console.log('success section');
res.send(JSON.parse(data.toString()));
}
});
I believe I understand your question...
if( response.statusCode === '401' ){
// alert
console.log('validation errors')
// get validation errors
res.status(401).send(yourValidationErrorsFound);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.