1.0.0 • Published 4 years ago

mongo-error-handler v1.0.0

Weekly downloads
4
License
ISC
Repository
-
Last release
4 years ago

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:example@ex.com} already exists"
  let errors = new Error(mongoErrors(err));

  console.log(errors);

  next(errors); // throw an error with mongo error message
});

Errors List

Field NameMessage
required"Password is required."
unique"{email:example@ex.com} 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.