@amariug/errors-and-middlewares v1.0.2
@amariug/errors-and-middlewares
An npm library or package containing a number of middlewares and error handlers abstracted from the amari-dmts repository to enhance modularity and reusability across different services and the client.
This package takes care of custom error handling, checking the current user status, requirung user authentication to access a given endpoint and validating user requests.
Installation
The package can be installed from the npm registry using this command;
npm install @amariug/errors-and-middlewares
The above command will install the latest version of the package.
To install a particular version of this package, use this command;
npm install @amariug/errors-and-middlewares@<package version>
for example
npm install @amariug/errors-and-middlewares@1.0.0
Alternatively, to update your currently installed version to the latest version, use this command;
npm update @amariug/errors-and-middlewares
error handlers
The error handler include;
BadRequestError
DatabaseConnectionError
NotFoundError
NotAuthorizedError
RequestValidationError
CustomError
authentication middlewares
The authentication middlewares include;
currentUser
requireAuth
error handling middlewares
The error handling middlewares include;
errorHandler
request validation middlewares
The validation middlewares include;
validateRequest
Usage
You can the use this package by importing the URL variables, for example;
...
import {
currentUser,
NotFoundError,
requireAuth,
validateRequest,
} from "@amariug/errors-and-middlewares";
import { DELIVERIES_API_URL } from "@amariug/urls"
...
router.post(
DELIVERIES_API_URL,
currentUser,
NotFoundError
requireAuth,
validateRequest,
...
)