Skip to content

Commit

Permalink
refactor(router): remove error handlers from the router
Browse files Browse the repository at this point in the history
This allows to use multiple openapi middlewares for the same app.

BREAKING CHANGE: Error handling must be confgured outside of the middleware.
  • Loading branch information
aleksandryackovlev committed Jan 31, 2022
1 parent c7fdf85 commit 3af3fc7
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 15 deletions.
8 changes: 0 additions & 8 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,5 @@ export const createMockMiddleware = ({
return res.locals.operation ? res.locals.operation.generateResponse(req, res) : next();
});

router.use((req, res) => {
res.status(404).send({ message: 'Not found' });
});

router.use((err: Error, req: express.Request, res: express.Response): void => {
res.status(500).send({ message: 'Something broke!' });
});

return router;
};
7 changes: 0 additions & 7 deletions test/integration.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,6 @@ describe('middleware', () => {
expect(typeof response.body.name).toBe('string');
});

it('should return an 404 error response if the given url does not exist', async () => {
const response = await request.get('/api/pet-not-exist/2');

expect(response.status).toBe(404);
expect(response.body).toHaveProperty('message', 'Not found');
});

it('should return an 400 error response if request body is not valid', async () => {
const response = await request
.post('/api/pet')
Expand Down

0 comments on commit 3af3fc7

Please sign in to comment.