mongo-error-handler
v1.0.0
Published
mongo errors handler
Readme
Mongo Error Handler
A Mongo DataBase Errors Handler Package , Formate mongo error message
Installation
Install via NPM:
npm install mongo-error-handler
Usage
javascript
const mongoErrors = require('mongo-error-handler');
try{
// mongo code here which throws any type of errors
}catch((err) => {
// return with mongo errors message
// output => "{email:[email protected]} already exists"
let errors = new Error(mongoErrors(err));
console.log(errors);
next(errors); // throw an error with mongo error message
});Errors List
| Field Name | Message | | ---------- | ----------------------------------------------------------------- | | required | "Password is required." | | unique | "{email:[email protected]} already exists" | | type | "password is a Number" | | match | "email is invalid (ex.com)." | | minlength | " password (12345) is less than minimum allowed value (6)." | | maxlength | " name (ali sabry) is longer than the maximum allowed length (6). |
License
This project is licensed under the terms of the MIT license.
