1.0.6 • Published 3 years ago

@valbo/not-found-middleware v1.0.6

Weekly downloads
87
License
MIT
Repository
github
Last release
3 years ago

@valbo/not-found-middleware

Express middleware that throws a not found error.

npm (scoped) semantic-release Build Status Coverage Status Known Vulnerabilities

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"
  }
}
1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.3

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago

1.0.0

3 years ago