Open kaihendry opened 2 years ago
You can do something like this;
// in app.js
app.get('/', async (req, res, next) => {
try {
//* logic here
throw new Error('test')
} catch (err) {
next(err)
}
})
Not tested but it should work and i think you will get this json response(http://localhost:3000)
{
"error":{
"status":500,
"message":"test"
}
}
Or you can use express 5 instead, route handlers or middleware that return a Promise
will call next(value)
automatically when they reject or throw an error. So, you don't have to use try catch
statement.
Hi, love this starter, but how do I allow for async code in the handler?