Handling errors using middleware

suggest change

This 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
  }
})

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents