serializableerror
v0.0.0
Published
Errors that will JSON.stringify()
Downloads
1
Readme
SerializableError
Errors that will JSON.stringify()
. By default if you try and pass an error into JSON.stringify()
it does not stringify the properties of the error. This does, but still allows you all the features of native Error
s including being thrown.
Install
$ npm install serializableerror
Usage
var SerializableError = require('serializableerror');
var error = new SerializableError('An error has occured');
// instances of Error can be passed in also
var error = SerializableError(new Error('An error has occured'));
JSON.stringify(error);
// =>
// {
// name: 'Error',
// message: 'An error has occured',
// fileNumber: int, // only in mozilla
// columnNumber: int, // only in mozilla
// fileName: 'String', // only in mozilla
// stack: 'Error: Testing SerializableError
// at callFn (/usr/local/lib/node_modules/mocha/lib/runnable.js:223:21)
// at Test.Runnable.run (/usr/local/lib/node_modules/mocha/lib/runnable.js:216:7)
// at Runner.runTest (/usr/local/lib/node_modules/mocha/lib/runner.js:373:10)
// at /usr/local/lib/node_modules/mocha/lib/runner.js:451:12
// at next (/usr/local/lib/node_modules/mocha/lib/runner.js:298:14)
// at /usr/local/lib/node_modules/mocha/lib/runner.js:308:7
// at next (/usr/local/lib/node_modules/mocha/lib/runner.js:246:23)
// at Object._onImmediate (/usr/local/lib/node_modules/mocha/lib/runner.js:275:5)
// at processImmediate [as _immediateCallback] (timers.js:336:15)'
// _error: {} // Error object
// }
Please note the stack above is from the test suite
Tests
Test suite runs in Mocha.
$ npm test
License
(The MIT License)
Copyright (c) 2014 TJ Krusinski <[email protected]>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the 'Software'), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.