Skip to content

A simple mongoose plugin that normalize mongoose errors

License

Notifications You must be signed in to change notification settings

kasongoyo/mongoose-errors

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

mongoose-errors

Simple mongoose plugin to normalize mongoose errors using http-errors. This plugin intercept mongoose errors to make them http-errors i.e errors with status code property

Prerequisites

Installing

npm i --save mongoose-errors

Usage

Simple example

const MongooseErrors = require('mongoose-errors')
const ModelSchema = new Schema({
    requiredField: {
        type: String,
        required: true
    }
});

ModelSchema.plugin(MongooseErrors);

Model = mongoose.model('ModelName', ModelSchema);

Model
    .create(test)
    .catch(error => {
        console.log(error.statusCode);
        // print 400 which is http bad request error code
        done();
    });
           

Testing

  • Clone this repository

  • Install all development dependencies

$ npm install
  • Then run test
$ npm test

Built With

  • npm - Used as the project core technology and build tool

Versioning

We use SemVer for versioning. For the versions available, see the tags on this repository.

Authors

  • Isaac Kasongoyo - Initial work

License

This project is licensed under the MIT License - see the LICENSE.md file for details

About

A simple mongoose plugin that normalize mongoose errors

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 3

  •  
  •  
  •