1.2.8 • Published 7 years ago

error-format-handler v1.2.8

Weekly downloads
-
License
MIT
Repository
-
Last release
7 years ago

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-handler

Running 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

1.2.8

7 years ago

1.2.7

7 years ago

1.2.6

7 years ago

1.2.5

7 years ago

1.2.4

7 years ago

1.2.3

7 years ago

1.2.2

7 years ago

1.2.1

7 years ago

1.2.0

7 years ago

1.1.0

7 years ago

1.0.0

7 years ago