What is this?
It a library for providing centralized error and exception handling with mongo DB. It is mainly used by Indian Aces Organization in their different projects.
Installation
npm i @dotcom-gosahi/centralized-exception-and-error-handling
Then...
const errorHandler = require('@dotcom-gosahi/centralized-exception-and-error-handling');
app.use(errorHandler(
{
environment: ENV,
configuration: {
connection: db,
errorDbName: error_db_Name
}
}));
Then...
const { APIError, httpErrorCodes} = require('@dotcom-gosahi/centralized-exception-and-error-handling');
res.status(httpErrorCodes.CREATED).json({ message: 'Inserted Successfully!' });
next(APIError.BadRequest(err.message));
Options
httpErrorCodes has following error codes: * OK * CREATED * BAD_REQUEST * UNAUTHORIZED * NOT_FOUND * INTERNAL_SERVER * UPDATED
Environments - LOCAL / TEST / DEV / PROD
APIError has following methods: * BadRequest * UnathorisedRequest * NotFoundRequest * ServerError