# error-format-handler

> Error handler for NodeJS applications

Latest version **1.2.8** (published 2017-07-28) · MIT license · 0 weekly downloads

## Install

```sh
npm install error-format-handler
pnpm add error-format-handler
yarn add error-format-handler
bun add error-format-handler
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.2.8 |
| Published | 2017-07-28 |
| First published | 2017-07-28 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=8.2.1 |
| Dependencies | 0 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Bruno Sartori |
| Maintainers | brunosartori |

## Links

- npm: https://www.npmjs.com/package/error-format-handler
- npm.io page: https://npm.io/package/error-format-handler

## Recent versions

- 1.2.8 (latest) — 2017-07-28
- 1.2.7 — 2017-07-28
- 1.2.6 — 2017-07-28
- 1.2.5 — 2017-07-28
- 1.2.4 — 2017-07-28
- 1.2.3 — 2017-07-28
- 1.2.2 — 2017-07-28
- 1.2.1 — 2017-07-28
- 1.2.0 — 2017-07-28
- 1.1.0 — 2017-07-28
- 1.0.0 — 2017-07-28

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

## Running the tests

No tests specified yet. :(

  ## Contributing

  Please read [CONTRIBUTING.md](https://gist.github.com/PurpleBooth/b24679402957c63ec426) for details on our code of conduct, and the process for submitting pull requests to us.

  ## Authors

  * **Bruno Sartori** - *Initial work* - [bruno-sartori](https://github.com/bruno-sartori)

  ## License

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

---
_Source: https://npm.io/package/error-format-handler · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
