Sunday 23 July 2017

Handling Operational Errors

Hi,I have code that updates data in a database (I'm using Sequelize as ORM) and passes the status of update request to the client (I have vuejs on the front end). The code works for my purposes but I would like to know if there are 'better' ways to handle error cases.my code below:app.patch('/api/device/updateshipment', function(req, res) { Device.update({ so_number: req.body.so_number, shipment_date: req.body.shipment_date }, { where: { serial_number: req.body.serial_number } }) .then(function(updatedDevices) { if(updatedDevices[0]) { res.status(200).end('Shipment details updated'); } else { res.status(404).end('Serial Number not found'); } }) .catch(function(err) { console.log(err) }) In the front end, the update status message (e.g. 'Shipment details updated') is then displayed to the user.How would I make use of the Error object in the case above (and is using Error object in this case considered best practice? Why?). Any other recommendations welcome!Thanks in advance!!

Submitted July 24, 2017 at 02:34AM by raccoonranger73

No comments:

Post a Comment