@@ -431,7 +431,7 @@ describe('Class: Router - Error Handling', () => {
431
431
} ) ;
432
432
} ) ;
433
433
434
- it ( 'handles throwing a built in error from the error handler' , async ( ) => {
434
+ it ( 'handles throwing a built in NotFound error from the error handler' , async ( ) => {
435
435
// Prepare
436
436
const app = new Router ( ) ;
437
437
@@ -458,4 +458,34 @@ describe('Class: Router - Error Handling', () => {
458
458
isBase64Encoded : false ,
459
459
} ) ;
460
460
} ) ;
461
+
462
+ it ( 'handles throwing a built in MethodNotAllowedError error from the error handler' , async ( ) => {
463
+ // Prepare
464
+ const app = new Router ( ) ;
465
+
466
+ app . errorHandler ( BadRequestError , async ( ) => {
467
+ throw new MethodNotAllowedError (
468
+ 'This error is thrown from the error handler'
469
+ ) ;
470
+ } ) ;
471
+
472
+ app . get ( '/test' , ( ) => {
473
+ throw new BadRequestError ( 'test error' ) ;
474
+ } ) ;
475
+
476
+ // Act
477
+ const result = await app . resolve ( createTestEvent ( '/test' , 'GET' ) , context ) ;
478
+
479
+ // Assess
480
+ expect ( result ) . toEqual ( {
481
+ statusCode : HttpErrorCodes . METHOD_NOT_ALLOWED ,
482
+ body : JSON . stringify ( {
483
+ statusCode : HttpErrorCodes . METHOD_NOT_ALLOWED ,
484
+ error : 'MethodNotAllowedError' ,
485
+ message : 'This error is thrown from the error handler' ,
486
+ } ) ,
487
+ headers : { 'content-type' : 'application/json' } ,
488
+ isBase64Encoded : false ,
489
+ } ) ;
490
+ } ) ;
461
491
} ) ;
0 commit comments