Add not found handler

This commit is contained in:
rijkvanzanten
2020-06-16 14:54:49 -04:00
parent c6aaa28187
commit bf76c2b4cc
2 changed files with 10 additions and 0 deletions

View File

@@ -5,11 +5,13 @@ import express from 'express';
import bodyParser from 'body-parser';
import { errorHandler } from './error';
import itemsRouter from './routes/items';
import notFoundHandler from './routes/not-found';
const app = express()
.disable('x-powered-by')
.use(bodyParser.json())
.use('/items', itemsRouter)
.use(notFoundHandler)
.use(errorHandler);
export default app;

8
src/routes/not-found.ts Normal file
View File

@@ -0,0 +1,8 @@
import { RequestHandler } from 'express';
import APIError, { ErrorCode } from '../error';
const notFound: RequestHandler = (req, res, next) => {
throw new APIError(ErrorCode.NOT_FOUND, `Route ${req.path} not found.`);
};
export default notFound;