1.0.20 • Published 5 years ago
@hiroit/common v1.0.20
Common Modules for Error Handling & Middlewares Used in Ticketing Project
Errors
BadRequestErrorContains a `400` status code and an arbitrary messageCustomErrorA base class to contain status code along with messageDatabaseConnectionErrorGeneric error for database connection issuesNotAuthorizedErrorContains a `401` status code along with `Unauthorized` messageNotFoundErrorContains a `400` status code along with `NotFound` messageRequestValidationErrorTo be used with `express-validator` for validation of incoming requests
Middlewares
currentUserA middleware to extract `jwt` token from cookie in request headererrorHandlerA middleware to return serialized error messages as below: ```json { "errors": [ { message: "message", field: "input field" } ] } ```requireAuthA middleware to detect login statusvalidateRequestA middleware to throw custom errors from validation of user input