Eg:
const Zinky = require('zinky');
var app = new Zinky({
aliases: {
'': 'home'
'customers': 'users'
},
catcher: function(req, res) {
console.log(req.error);
res.deliver(500, 'Oooops something went wrong!');
}
});
app.listen();
Now we'll simulate an error to test the catcher. Add this operation to 'app_modules/home/index.js':
GET_simulate(req, res) {
a = b;
}
Visit localhost:3000/simulate
Even if we don't define a catcher, ZinkyJS has built-in function that logs the error then responds 500 as status code and 'Internal Server Error' as message. Here is its code:
catcher(req, res) {
console.log(req.error);
res.deliver(500, 'Internal Server Error');
}