JSPM

node-error-for-humans

0.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q21220F
  • License MIT

Add to Error class `toHumans()` function to get a more detailed error reason from nodejs error, in case the Error object is not a nodejs Error, returns the toString() message

Package Exports

  • node-error-for-humans

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (node-error-for-humans) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

Node Errors for Humans

A nice lib to get more detailed description for System Error messages get from nodejs, based on Error code.

The lib supports multilanguage, easy it is very easy to change the message for each code.

The messages in english were taken from the nodejs docs link

Installation

npm install node-errors-for-humans --save

Usage

var errorForHumans = require("node-errors-for-humans");

try {
    ...
} catch(err) {
    // err.code == "ECONNREFUSED"
    err.toHumans();
}
// output: (Connection refused): No connection could be made because the target machine actively refused it. This usually results from trying to connect to a service that is inactive on the foreign host. (ECONNREFUSED)

Change localization

var errorForHumans = require("node-errors-for-humans");
errorForHumans.humanLanguage = "en";

Add a new language

var errorForHumans = require("node-errors-for-humans");
errorForHumans.setMessageDictionary({
    "ECONNREFUSED": "A conexao foi rejeitada"
}, "pt-br");

Changing a specific message

var errorForHumans = require("node-errors-for-humans");
errorForHumans.setCodeHumanMessage("ECONNREFUSED", "A conexao foi rejeitada!", "pt-br");