error_handler.js 355 B

12345678910111213141516
  1. 'use strict';
  2. module.exports = () => {
  3. return async function errorHandler(ctx, next) {
  4. try {
  5. await next();
  6. } catch (err) {
  7. console.log(err);
  8. // console.log(err.code);
  9. const { message } = err;
  10. const json = JSON.parse(message);
  11. console.log(json);
  12. // ctx.body = json;
  13. ctx.status = 400;
  14. }
  15. };
  16. };