https://github.com/postmanlabs/serialised-error
Serialises error object to normal object
https://github.com/postmanlabs/serialised-error
Last synced: 3 months ago
JSON representation
Serialises error object to normal object
- Host: GitHub
- URL: https://github.com/postmanlabs/serialised-error
- Owner: postmanlabs
- License: apache-2.0
- Created: 2015-08-24T16:28:31.000Z (over 10 years ago)
- Default Branch: develop
- Last Pushed: 2024-02-22T15:09:52.000Z (almost 2 years ago)
- Last Synced: 2025-06-09T02:11:33.053Z (7 months ago)
- Language: JavaScript
- Size: 38.1 KB
- Stars: 4
- Watchers: 6
- Forks: 6
- Open Issues: 17
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Serialised Error
This module attempts to convert an error object into a regular JavaScript object. This is useful if an error object has
to be stored and operated upon.
## Usage
```javascript
var SerialisedError = require('serialised-error');
// assuming you have an error
var someError = new Error("This is a test error");
// convert the error to object (new operator is optional)
var serialisedError = new SerialisedError(someError);
// convert the serialised error to JSON
console.log(JSON.parse(serialisedError));
// this outputs:
// {"name": "Error", "message": "This is a test error", "stack": "Error\n at ..."}
```
## Adding additional meta information to error
Passing a second argument as `true` to the `SerialisedError` constructor adds the following keys to the serialised object.
| Property | Description |
| --------------- | ----------- |
| `checksum` | a `SHA1` checksum of the error that is constant for same name, message and stack |
| `id` | a random `UUID` (v4) of the error |
| `timestamp` | the time when the error was serialised |
| `timestampISO` | the time (in ISO format) when the error was serialised |
| `stacktrace` | a prettified array of stack traces |
## Installation
```terminal
npm install serialised-error;
```