customError.filter.ts 384 B

123456789101112131415
  1. import { Catch } from '@midwayjs/core';
  2. import { Context } from '@midwayjs/koa';
  3. import { ServiceError } from '../error/service.error';
  4. @Catch(ServiceError)
  5. export class CustomErrorFilter {
  6. async catch(err: Error, ctx: Context) {
  7. // 所有的未分类错误会到这里
  8. return {
  9. errcode: err['code'],
  10. errmsg: err.message,
  11. details: err.stack,
  12. };
  13. }
  14. }