Skip to content

Latest commit

 

History

History
30 lines (24 loc) · 822 Bytes

README.md

File metadata and controls

30 lines (24 loc) · 822 Bytes

@open-node/errors

make the error object with custom defines

Build status codecov

Installation

npm i @open-node/errors --save

Usage

  • your node.js process code
const Errors = require('@open-node/errors');

const defines = [
  ['yourErrorCode', 'Your error message, allow add variable, eg: %s']
  ['yourErrorCode2', 'Your error message, allow add variable, eg: %s, %d']
];
const errors = Errors(defines);

// usage in your code
try {
  ...
  ...
} catch (e) {
  const error = errors.yourErrorCode(e.message); // returns error be instanceOf Error
  writeErrorLog(error);
}