import { ApplicationContext, Catch, IMidwayContainer, Inject } from '@midwayjs/core';
import { Context } from '@midwayjs/koa';
import { ServiceError } from '../error/service.error';

// 自定义异常
@Catch([ServiceError])
export class CustomErrorFilter {
  @Inject()
  ctx: Context;
  @ApplicationContext()
  applicationContext: IMidwayContainer;
  async catch(err: Error, ctx: Context) {
    console.error(err);
    // 接收并处理系统定义错误
    return { errcode: err.message, stack: err.stack };
  }
}
