Handling errors using middleware
suggest changeThis is Koa middleware: ctx is the context and next is a function. Express error middleware is different. It is a four-argument function (err, req, res, next) registered last.
app.use(async (ctx, next) => {
try {
await next() // attempt to invoke the next middleware downstream
} catch (err) {
handleError(err, ctx) // define your own error handling function
}
})
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents