Emitting errors

It is recommended that you emit an error on the application itself. This is useful for centralized error reporting or logging. This also helps to retain the default behavior of Koa for errors. Errors can be emitted using the ctx.app.emit() method:

app.use(async (ctx, next) => {
  try {
    await next();
  } catch (err) {
    ctx.status = err.status || 500;
    ctx.body = err.message;
    ctx.app.emit('error', err, ctx);
  }
});

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.221.165.246