Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jondubois/errorsponge
A simple utility library for dehydrating errors for transmission and then rehydrating them.
https://github.com/jondubois/errorsponge
client-server error-handling errors javascript nodejs serializer
Last synced: 12 days ago
JSON representation
A simple utility library for dehydrating errors for transmission and then rehydrating them.
- Host: GitHub
- URL: https://github.com/jondubois/errorsponge
- Owner: jondubois
- Created: 2017-02-19T12:15:08.000Z (almost 8 years ago)
- Default Branch: master
- Last Pushed: 2017-02-19T14:02:28.000Z (almost 8 years ago)
- Last Synced: 2024-12-16T13:09:18.578Z (24 days ago)
- Topics: client-server, error-handling, errors, javascript, nodejs, serializer
- Language: JavaScript
- Homepage:
- Size: 478 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# ErrorSponge
A simple utility library for dehydrating errors for transmission and then rehydrating them.## Install
```
npm install errorsponge
```## API
```
var ErrorSponge = require('errorsponge').ErrorSponge;
```### new ErrorSponge([options])
Create a new ErrorSponge utility to dehydrate and hydrate errors.
The `options` object is optional and can have the following properties:- `unserializableErrorProperties` - A list of properties (strings) on Error objects which should be ignored when dehydrating.
### dehydrateError(error, [includeStackTrace])
Convert a JavaScript Error object into a serializable JSON object which can then easily be converted into a string using `JSON.stringify()` and sent across the network.
If `includeStackTrace` is specified and set to true, the error's stack trace will be included as part of the dehydrated JSON object.Returns a plain Object.
### hydrateError(dehydratedError)
Convert a dehydrated JSON error back into a JavaScript Error object.
Returns an Error object.
## Conventions
To make error handling easier, it is recommended that all Error objects have a custom `name` which allows your code to quickly identify the type of the error after it has been rehydrated.
A good way to instantiate errors might be (example):```
var err = new Error('The provided object did not have all the required properties');
err.name = 'MissingPropertiesError';
```