Skip to content

Commit 3102fef

Browse files
committed
improved coverage
1 parent 246510f commit 3102fef

File tree

1 file changed

+31
-1
lines changed

1 file changed

+31
-1
lines changed

packages/event-handler/tests/unit/rest/Router/error-handling.test.ts

Lines changed: 31 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -431,7 +431,7 @@ describe('Class: Router - Error Handling', () => {
431431
});
432432
});
433433

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 () => {
435435
// Prepare
436436
const app = new Router();
437437

@@ -458,4 +458,34 @@ describe('Class: Router - Error Handling', () => {
458458
isBase64Encoded: false,
459459
});
460460
});
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+
});
461491
});

0 commit comments

Comments
 (0)