File tree Expand file tree Collapse file tree 1 file changed +18
-1
lines changed
Expand file tree Collapse file tree 1 file changed +18
-1
lines changed Original file line number Diff line number Diff line change 1- import { BadRequestException , NotFoundException } from '@nestjs/common' ;
1+ import {
2+ BadRequestException ,
3+ HttpException ,
4+ NotFoundException ,
5+ } from '@nestjs/common' ;
26import {
37 HOST_METADATA ,
48 MODULE_PATH ,
@@ -185,11 +189,24 @@ export class RoutesResolver implements Resolver {
185189 // encoding, e.g. '%FF' (#8915)
186190 case err instanceof SyntaxError || err instanceof URIError :
187191 return new BadRequestException ( err . message ) ;
192+ case this . isHttpFastifyError ( err ) :
193+ return new HttpException ( err . message , err . statusCode ) ;
188194 default :
189195 return err ;
190196 }
191197 }
192198
199+ private isHttpFastifyError (
200+ error : any ,
201+ ) : error is Error & { statusCode : number } {
202+ // condition based on this code - https://github.com/fastify/fastify-error/blob/d669b150a82968322f9f7be992b2f6b463272de3/index.js#L22
203+ return (
204+ error . statusCode !== undefined &&
205+ error instanceof Error &&
206+ error . name === 'FastifyError'
207+ ) ;
208+ }
209+
193210 private getModulePathMetadata ( metatype : Type < unknown > ) : string | undefined {
194211 const modulesContainer = this . container . getModules ( ) ;
195212 const modulePath = Reflect . getMetadata (
You can’t perform that action at this time.
0 commit comments