Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

关于[数据流异常拦截器]的疑问 #22

Open
SirM2z opened this issue Jun 22, 2019 · 0 comments
Open

关于[数据流异常拦截器]的疑问 #22

SirM2z opened this issue Jun 22, 2019 · 0 comments

Comments

@SirM2z
Copy link

SirM2z commented Jun 22, 2019

你好,从你的开源代码中学到很多,非常感谢!

数据流异常拦截器按照 README 的描述是:当控制器所需的 Promise service 发生错误时,错误将在此被捕获

有两个个疑问:

  1. 该拦截器只是收集了错误信息并抛出异常(CustomException),仅仅是这样的需求的话,为什么不直接通过过滤器(HttpExceptionFilter)捕获错误呢?因为拦截器抛出的异常(CustomException)最终依然是交给过滤器(HttpExceptionFilter)来处理,而过滤器的第一个参数 exception 是有完整的错误信息的
  2. 该拦截器中抛出异常的代码是 throwError(new CustomException({ message, error }, statusCode));,这样的写法会导致在终端中打印出 抛出异常的无效堆栈信息
    image,并没有记录实质的请求相关的内容

我在生产环境中并没有关闭 NestJS Logger,所以我在 HttpExceptionFilter 中多加了些打印日志

Logger.error(
  `${request.method} ${request.url}`,
  JSON.stringify(errorResponse),
  'HttpExceptionFilter',
);

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant