1- import {
2- BadRequestException ,
3- HttpException ,
4- Module ,
5- Post ,
6- VersioningType ,
7- } from '@nestjs/common' ;
1+ import { Module , Post , VersioningType } from '@nestjs/common' ;
82import { MODULE_PATH } from '@nestjs/common/constants' ;
93import { expect } from 'chai' ;
104import * as sinon from 'sinon' ;
@@ -18,7 +12,6 @@ import { GraphInspector } from '../../inspector/graph-inspector';
1812import { SerializedGraph } from '../../inspector/serialized-graph' ;
1913import { RoutesResolver } from '../../router/routes-resolver' ;
2014import { NoopHttpAdapter } from '../utils/noop-adapter.spec' ;
21- import { createError as createFastifyError } from '@fastify/error' ;
2215
2316describe ( 'RoutesResolver' , ( ) => {
2417 @Controller ( 'global' )
@@ -320,61 +313,6 @@ describe('RoutesResolver', () => {
320313 } ) ;
321314 } ) ;
322315
323- describe ( 'mapExternalExceptions' , ( ) => {
324- describe ( 'when exception prototype is' , ( ) => {
325- describe ( 'SyntaxError' , ( ) => {
326- it ( 'should map to BadRequestException' , ( ) => {
327- const err = new SyntaxError ( ) ;
328- const outputErr = routesResolver . mapExternalException ( err ) ;
329- expect ( outputErr ) . to . be . instanceof ( BadRequestException ) ;
330- } ) ;
331- } ) ;
332- describe ( 'URIError' , ( ) => {
333- it ( 'should map to BadRequestException' , ( ) => {
334- const err = new URIError ( ) ;
335- const outputErr = routesResolver . mapExternalException ( err ) ;
336- expect ( outputErr ) . to . be . instanceof ( BadRequestException ) ;
337- } ) ;
338- } ) ;
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- } ) ;
368- describe ( 'other' , ( ) => {
369- it ( 'should behave as an identity' , ( ) => {
370- const err = new Error ( ) ;
371- const outputErr = routesResolver . mapExternalException ( err ) ;
372- expect ( outputErr ) . to . be . eql ( err ) ;
373- } ) ;
374- } ) ;
375- } ) ;
376- } ) ;
377-
378316 describe ( 'registerNotFoundHandler' , ( ) => {
379317 it ( 'should register not found handler' , ( ) => {
380318 routesResolver . registerNotFoundHandler ( ) ;
0 commit comments