node.js - Error Handling with nested catch -
i encountered problem during error handling in presence of several catch nested, because object response called more times.
objecta.create({}) .then(function (objecta) { objectb.create({ objectaid: objecta.id, name: objectadata.name, cropid: objectadata.crop }) .then(function (objectb) { objectadata.collection.foreach(function () { objectc.create({ objectbid: objectb.id, }) .catch(function (err) { console.log('# # # catch 1 # # #'); next({status: 500, data: err}); }) }) }) .catch(function (err) { console.log('# # # catch 2 # # #'); next({status: 500, data: err}); }); //response http 200 next({status: 200, data: objecta.id}); }) .catch(function (err) { console.log('# # # catch 3 # # #'); next({status: 500, data: err}); })
this happens when there's error inside catch (for example # catch 2 #
) , next({status: 500, data: err});
function called next({status: 200, data: objecta.id});
i receive suggestion how handle errors in situation.
Comments
Post a Comment