Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/saintedlama/generaterr
A simple custom error generator for node.js
https://github.com/saintedlama/generaterr
Last synced: 2 months ago
JSON representation
A simple custom error generator for node.js
- Host: GitHub
- URL: https://github.com/saintedlama/generaterr
- Owner: saintedlama
- Created: 2014-09-29T07:02:58.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2017-05-31T21:36:54.000Z (over 7 years ago)
- Last Synced: 2024-09-25T12:21:49.019Z (3 months ago)
- Language: JavaScript
- Size: 20.5 KB
- Stars: 4
- Watchers: 2
- Forks: 2
- Open Issues: 28
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Generaterr
[![Build Status](https://travis-ci.org/saintedlama/generaterr.svg?branch=master)](https://travis-ci.org/saintedlama/generaterr)
[![Coverage Status](https://coveralls.io/repos/github/saintedlama/generaterr/badge.svg?branch=master)](https://coveralls.io/github/saintedlama/generaterr?branch=master)Generates custom and valid node.js error functions for node.js.
## Installation
npm install generaterr --save
## Usage
#### Basis Usage
var ParseError = generaterr('ParseError');
try
{
throw new ParseError('Could not parse file due to missing semicolons');
} catch(e) {
console.log(e.message);
console.log(e.name);
console.log(e.stack);
}#### Formatting messages
var ParseError = generaterr('ParseError');
try
{
throw new ParseError('Could not parse file "%s" due to missing semicolons at line %d:%d', 'input.js', 10, 12);
} catch(e) {
// Message: 'Could not parse file "input.js" due to missing semicolons at line 10:12'
}#### Generator Arguments
var NotFoundError = generaterr('NotFoundError', { status : 404 });
var notFoundError = new NotFoundError('Could find resource /api/random/numbers');
console.log(notFoundError.status);
// Prints '404'
#### Constructor Arguments
var ParseError = generaterr('ParseError');
var err = new ParseError('Could not parse file "%s" due to missing semicolons at line %d:%d', 'input.js', 10, 12, { status : 'FATAL' });
console.log(err.message)
// Prints 'Could not parse file "input.js" due to missing semicolons at line 10:12'console.log(err.status)
// Prints 'FATAL'## Options
#### captureStackTrace, defaults to 'true'
Turning off stack trace generation may be useful for business logic exceptions that do not require a stack trace.var ParseError = generaterr('ParseError', null, { captureStackTrace : false });