//ERROR Handler. Define this middleware first //This catches all the sync errors App.use(async function(ctx, next) { try { //All the following middleware executions are bound to a try/catch block await next(); } catch(error) { ctx.status = error.status || 500; ctx.app.emit('error', error, ctx); } });