1
- import {
2
- BadRequestException ,
3
- HttpException ,
4
- Module ,
5
- Post ,
6
- VersioningType ,
7
- } from '@nestjs/common' ;
1
+ import { Module , Post , VersioningType } from '@nestjs/common' ;
8
2
import { MODULE_PATH } from '@nestjs/common/constants' ;
9
3
import { expect } from 'chai' ;
10
4
import * as sinon from 'sinon' ;
@@ -18,7 +12,6 @@ import { GraphInspector } from '../../inspector/graph-inspector';
18
12
import { SerializedGraph } from '../../inspector/serialized-graph' ;
19
13
import { RoutesResolver } from '../../router/routes-resolver' ;
20
14
import { NoopHttpAdapter } from '../utils/noop-adapter.spec' ;
21
- import { createError as createFastifyError } from '@fastify/error' ;
22
15
23
16
describe ( 'RoutesResolver' , ( ) => {
24
17
@Controller ( 'global' )
@@ -320,61 +313,6 @@ describe('RoutesResolver', () => {
320
313
} ) ;
321
314
} ) ;
322
315
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
-
378
316
describe ( 'registerNotFoundHandler' , ( ) => {
379
317
it ( 'should register not found handler' , ( ) => {
380
318
routesResolver . registerNotFoundHandler ( ) ;
0 commit comments