https://github.com/kasongoyo/mongoose-errors
A simple mongoose plugin that normalize mongoose errors
https://github.com/kasongoyo/mongoose-errors
Last synced: 9 months ago
JSON representation
A simple mongoose plugin that normalize mongoose errors
- Host: GitHub
- URL: https://github.com/kasongoyo/mongoose-errors
- Owner: kasongoyo
- License: mit
- Created: 2019-04-03T04:29:04.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-02T21:42:27.000Z (almost 3 years ago)
- Last Synced: 2025-03-10T05:06:10.121Z (10 months ago)
- Language: JavaScript
- Size: 480 KB
- Stars: 1
- Watchers: 1
- Forks: 1
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# mongoose-errors
Simple mongoose plugin to normalize mongoose errors using [http-errors](https://www.npmjs.com/package/http-errors). This plugin intercept mongoose errors to make them http-errors i.e errors
with status code property
## Prerequisites
- [Nodejs 7.6.0 or greater](https://nodejs.org)
- [Mongoose 4 or greater](https://mongoosejs.com/)
## Installing
```bash
npm i --save mongoose-errors
```
## Usage
Simple example
```bash
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
```sh
$ npm install
```
* Then run test
```sh
$ npm test
```
## Built With
- [npm](https://www.npmjs.com/) - Used as the project core technology and build tool
## Versioning
We use [SemVer](http://semver.org/) for versioning. For the versions available, see the [tags on this repository](https://github.com/kasongoyo/mongoose-errors/tags).
## Authors
* **Isaac Kasongoyo** - *Initial work*
## License
This project is licensed under the MIT License - see the [LICENSE.md](LICENSE.md) file for details