In my node backend, this is how I send the error message to the front end:
catch (err) {
res.status(500).json("UNEXPECTED ERROR. Please try again later.");
}
How do I access the error message in the backend? Is this correct?
catch (err) {
err.response.data;
}
You can access the error message like: error.message
I have tried in typescript this worked for me.
try {
throw new Error("UNEXPECTED ERROR. Please try again later.");
} catch (error: any) {
console.log(error!.message);
return res.status(400).send(error!.message);
}
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.