error-format-handler
v1.2.8
Published
Error handler for NodeJS applications
Readme
Error Format Handler
Format multiple NodeJS errors in an ordened way to respose
Motivation
When mongoose throws ValidationError it sends the error object like this:
"errors": {
"telefone2": {
"message": "Não é um telefone válido.",
"name": "ValidatorError",
"properties": {
"type": "user defined",
"message": "Não é um telefone válido.",
"path": "telefone2",
"value": "(17) 809-7542"
},
"kind": "user defined",
"path": "telefone2",
"value": "(17) 809-7542",
"$isValidatorError": true
},
"telefone1": {
"message": "Não é um telefone válido.",
"name": "ValidatorError",
"properties": {
"type": "user defined",
"message": "Não é um telefone válido.",
"path": "telefone1",
"value": "(17) 154-8437"
},
"kind": "user defined",
"path": "telefone1",
"value": "(17) 154-8437",
"$isValidatorError": true
}
},
"_message": "Validation failed",
"message": "Validation failed: telefone2: Não é um telefone válido., telefone1: Não é um telefone válido.",
"name": "ValidationError"
So i've decided to create a npm module that formats errors in objects more simpliest as possible.
Getting Started
Use the default export function giving the error from nodejs.
import errorFormatHandler from 'error-format-handler';
...
.catch(error => errorFormatHandler(error));
returns:
{
name: 'ValidationError',
errors: [
{
path: 'telefone2',
message: 'Não é um telefone válido.'
},
{
path: 'telefone1',
message: 'Não é um telefone válido.'
}
]
}
Installing
This package can be installed via npm:
npm install --save error-format-handlerRunning the tests
No tests specified yet. :(
Contributing
Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.
Authors
- Bruno Sartori - Initial work - bruno-sartori
License
This project is licensed under the MIT License - see the LICENSE.md file for details
