You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Is your feature request related to a problem? Please describe.
I noticed that the customErrorObject callback for pino-http was not being triggered when an error deriving from HttpException was thrown. This is because the built-in NestJS BaseExceptionFilter was kicking in, sending a response based on the status code/content of the exception. Using LoggerErrorInterceptor globally does not work because BaseExceptionFilter converts HttpException errors to a regular "successful" response. I would like my logging code to receive HttpException objects so I can log the error response bodies.
Describe the solution you'd like
It'd be nice if this library explained the case of HttpException and HttpException-derived errors not being caught by LoggerErrorInterceptor. Luckily, the code to work around the problem is pretty simple, and maybe nestjs-pino could provide an exception filter out of the box as an alternative to LoggerErrorInterceptor:
import{Catch,ArgumentsHost}from'@nestjs/common';import{BaseExceptionFilter}from'@nestjs/core';import{Response}from'express';
@Catch(Error)exportclassExceptionCapturingFilterextendsBaseExceptionFilter{catch(exception: Error,host: ArgumentsHost){// If `pino-http` sees this property, it will cause the error logging to// kick in.host.switchToHttp().getResponse<Response>().err=exception;super.catch(exception,host);}}
Describe alternatives you've considered
I tried using LoggerErrorInterceptor globally and on each individual controller; nothing was allowing the base exception filter to be bypassed.
Additional context
None so far.
The text was updated successfully, but these errors were encountered:
Is your feature request related to a problem? Please describe.
I noticed that the
customErrorObject
callback forpino-http
was not being triggered when an error deriving fromHttpException
was thrown. This is because the built-in NestJSBaseExceptionFilter
was kicking in, sending a response based on the status code/content of the exception. UsingLoggerErrorInterceptor
globally does not work becauseBaseExceptionFilter
convertsHttpException
errors to a regular "successful" response. I would like my logging code to receiveHttpException
objects so I can log the error response bodies.Describe the solution you'd like
It'd be nice if this library explained the case of
HttpException
andHttpException
-derived errors not being caught byLoggerErrorInterceptor
. Luckily, the code to work around the problem is pretty simple, and maybenestjs-pino
could provide an exception filter out of the box as an alternative toLoggerErrorInterceptor
:Here's an example of how to inject it globally:
Describe alternatives you've considered
I tried using
LoggerErrorInterceptor
globally and on each individual controller; nothing was allowing the base exception filter to be bypassed.Additional context
None so far.
The text was updated successfully, but these errors were encountered: