@valbo/not-found-middleware
v1.0.6
Published
Express middleware that throws a not found error
Downloads
2
Readme
@valbo/not-found-middleware
Express middleware that throws a not found error.
Install
npm install @valbo/not-found-middleware
Usage
This middleware sends a not found error via next() down the middleware chain. It is meant to be used as the last non-error middleware in the chain, to capture any url that has no router or middleware associated. It will include the request method and route in the message.
After this middleware there should be an error handler middleware that captures the error, like @valbo/error-handler-middleware.
import { notFoundMiddleware } from '@valbo/not-found-middleware';
import { errorHandlerMiddleware } from '@valbo/error-handler-middleware';
app.use(notFoundMiddleware);
app.use(errorHandlerMiddleware);
If a request is made to a route with no router or middleware associated, express would return:
{
"error": {
"status": 404,
"name": "NotFoundError",
"message": "POST /data not found"
}
}