Saturday, 13 July 2019

Returning an error from controller to a route

I'm working on the error handling in an Vue application that uses Express in Node:​router.put('/documents', async (req, res) => { const updateExistingAsset = await controllerSearch.updateExistingAsset(req.body); res.json(updateExistingAsset) })I'm attempting to return an error message from the "updateExistingAsset()" controller, but — so far — I have no idea how.​I've tried a plain return, a return with a new Error(), and:​return new Promise((resolve) => { return resolve(new Error(error)) })... but nothing works.​The error is valid, as it's part of a .then(function(error) {}) that is itself working (I'm writing out to a table in MySQL with the errors).

Submitted July 13, 2019 at 08:28PM by WayneSmallman

No comments:

Post a Comment