File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 33 Catch ,
44 ExceptionFilter ,
55 HttpException ,
6- HttpStatus ,
6+ HttpStatus , InternalServerErrorException ,
77} from '@nestjs/common' ;
88import { Request , Response } from 'express' ;
99import { logger } from '../logger' ;
@@ -34,7 +34,7 @@ class ErrorResponse {
3434
3535@Catch ( )
3636export class HttpExceptionFilter implements ExceptionFilter {
37- catch ( exception : HttpException , host : ArgumentsHost ) {
37+ catch ( exception : HttpException | Error , host : ArgumentsHost ) {
3838 const ctx = host . switchToHttp ( ) ;
3939 const response = ctx . getResponse < Response > ( ) ;
4040 const request = ctx . getRequest < Request > ( ) ;
@@ -44,12 +44,16 @@ export class HttpExceptionFilter implements ExceptionFilter {
4444 : HttpStatus . INTERNAL_SERVER_ERROR ;
4545 const { ip, method, url } = request ;
4646 logger . error (
47- `${ method } - ${ url } - ${ ip . split ( ':' ) . at ( - 1 ) } - ${ JSON . stringify (
47+ `${ method } - ${ url } - ${ ip ? .split ( ':' ) ? .at ( - 1 ) } - ${ JSON . stringify (
4848 exception ,
4949 ) } `,
5050 ) ;
5151
52- const exceptionResponse = exception . getResponse ( ) as {
52+ if ( ! ( exception instanceof HttpException ) ) {
53+ exception = new InternalServerErrorException ( exception . message ) ;
54+ }
55+
56+ const exceptionResponse = ( exception as HttpException ) . getResponse ( ) as {
5357 error : string ;
5458 message ?: string | string [ ] ;
5559 data ?: any ;
You can’t perform that action at this time.
0 commit comments