index.js 454 B

12345678910111213141516171819
  1. async function catchError(ctx, next) {
  2. try {
  3. await next();
  4. if (ctx.status === 404) ctx.throw(404);
  5. } catch(err) {
  6. let status = err.status || 500;
  7. // let message = e.message || 'Server Error!'
  8. ctx.status = status;
  9. ctx.state = {
  10. status: status,
  11. helpers: helpers,
  12. currentUser: null
  13. };
  14. await ctx.render('error/error', {});
  15. if (status == 500) {
  16. console.log('server error', err, ctx);
  17. }
  18. }
  19. }