Here's my chunk of code:
const getToken = async () => {
try {
const token = await axios.post(keys.sessionURL, {
email: keys.verificationEmail,
password: keys.verificationPassword,
});
} catch (err) {
throw new Error('Unable to establish a login session.'); // here I'd like to send the error to the user instead
}
};
So as you can see I'm connecting to external server in order to get a token. And that works. Now, I'd like to catch an error but this time not with 'throw new error' but I'd like to send it to the user, so I'd like to have something like this instead:
res.status(401).send('Unable to get a token');
But because I'm not inside the route handler I cannot use 'res'. How can I send it to the user then?
Thank you!