11import {
22 BadRequestException ,
3+ HttpException ,
34 Module ,
45 Post ,
56 VersioningType ,
@@ -17,6 +18,7 @@ import { GraphInspector } from '../../inspector/graph-inspector';
1718import { SerializedGraph } from '../../inspector/serialized-graph' ;
1819import { RoutesResolver } from '../../router/routes-resolver' ;
1920import { NoopHttpAdapter } from '../utils/noop-adapter.spec' ;
21+ import { createError as createFastifyError } from '@fastify/error' ;
2022
2123describe ( 'RoutesResolver' , ( ) => {
2224 @Controller ( 'global' )
@@ -334,6 +336,35 @@ describe('RoutesResolver', () => {
334336 expect ( outputErr ) . to . be . instanceof ( BadRequestException ) ;
335337 } ) ;
336338 } ) ;
339+ describe ( 'FastifyError' , ( ) => {
340+ it ( 'should map FastifyError with status code to HttpException' , ( ) => {
341+ const FastifyErrorCls = createFastifyError (
342+ 'FST_ERR_CTP_INVALID_MEDIA_TYPE' ,
343+ 'Unsupported Media Type: %s' ,
344+ 415 ,
345+ ) ;
346+ const error = new FastifyErrorCls ( ) ;
347+
348+ const result = routesResolver . mapExternalException ( error ) ;
349+
350+ expect ( result ) . to . be . instanceOf ( HttpException ) ;
351+ expect ( result . message ) . to . equal ( error . message ) ;
352+ expect ( result . getStatus ( ) ) . to . equal ( 415 ) ;
353+ } ) ;
354+
355+ it ( 'should return FastifyError without user status code to Internal Server Error HttpException' , ( ) => {
356+ const FastifyErrorCls = createFastifyError (
357+ 'FST_WITHOUT_STATUS_CODE' ,
358+ 'Error without status code' ,
359+ ) ;
360+ const error = new FastifyErrorCls ( ) ;
361+
362+ const result = routesResolver . mapExternalException ( error ) ;
363+ expect ( result ) . to . be . instanceOf ( HttpException ) ;
364+ expect ( result . message ) . to . equal ( error . message ) ;
365+ expect ( result . getStatus ( ) ) . to . equal ( 500 ) ;
366+ } ) ;
367+ } ) ;
337368 describe ( 'other' , ( ) => {
338369 it ( 'should behave as an identity' , ( ) => {
339370 const err = new Error ( ) ;
0 commit comments