Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/adriano-di-giovanni/node-error
A library of extendable custom errors for node.js
https://github.com/adriano-di-giovanni/node-error
Last synced: 1 day ago
JSON representation
A library of extendable custom errors for node.js
- Host: GitHub
- URL: https://github.com/adriano-di-giovanni/node-error
- Owner: adriano-di-giovanni
- License: mit
- Created: 2014-03-12T15:43:47.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2014-04-30T13:10:23.000Z (over 10 years ago)
- Last Synced: 2024-09-19T16:48:01.751Z (about 2 months ago)
- Language: JavaScript
- Size: 195 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# Error
Error is a library of extendable custom errors for node.js.
## Installation
```
npm node-error --save
```## Usage
Errors in the library can be instantiated directly
```javascript
var
LoggableError = require('node-error').LoggableError;throw new LoggableError('message');
```or extended using `.extend(name, [attributes])`:
```javascript
var
LoggableError = require('node-error').LoggableError;var
attributes = function () {
return {
memoryUsage: process.memoryUsage()
};
},
CustomError = LoggableError.extend('CustomError', attributes);
```The `attributes` argument to the `extend` method is optional.
It can be of type object or function.
The function executes upon error instantiation and it should return an object.```javascript
var
error = new CustomError('message');console.log(error.attributes);
```## Errors
### ExtendableError
ExtendableError is the base error to extend using `.extend` method.
### LoggableError
LoggableError is an error having the `stack` property enumerable.
### ProxiedError
```javascript
var
ProxiedError = require('node-error').ProxiedError;var
error = new ProxiedError(new Error());
```