how to define an error type in node js code example
Example 1: node js throw error
FactoryController.prototype.create = function (callback) {
throw new Error('An error occurred');
try {
this.check(function (check_result) {
callback(check_result);
});
} catch (ex) {
throw new Error(ex.toString());
}
}
FactoryController.prototype.create = function (callback) {
try {
this.check(function (check_result) {
throw new Error('An error occurred');
});
} catch (ex) {
throw new Error(ex.toString());
}
}
Example 2: node js type error
TypeError: res.status is not a function
at C:\Users\lenovo\Desktop\MERN\backend\app.js:16:8
at Layer.handle_error (C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\layer.js:71:5)
at trim_prefix (C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\index.js:315:13)
at C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\index.js:284:7
at Function.process_params (C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\index.js:335:12)
at Immediate.next (C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\index.js:275:10)
at Immediate.<anonymous> (C:\Users\lenovo\Desktop\MERN\backend\node_modules\express\lib\router\index.js:635:15)
at processImmediate (internal/timers.js:458:21)
reason:-(error,res,req,next) order of argument is incorrect req after before res
solution:-(error,req,res,next)