serialised-error
Advanced tools
+16
-6
@@ -1,5 +0,10 @@ | ||
| var SerialisedError = module.exports = function (err) { | ||
| var stacktrace = require('stack-trace'), | ||
| hash = require('object-hash'), | ||
| uuid = require('node-uuid'), | ||
| SerialisedError; | ||
| SerialisedError = function (err, decorate) { | ||
| // If the function is called without the `new` operator, then we do it on behalf of the callee | ||
| if (!(this instanceof SerialisedError)) { | ||
| return new SerialisedError(err); | ||
| return new SerialisedError(err, decorate); | ||
| } | ||
@@ -11,7 +16,12 @@ | ||
| }, this); | ||
| // add additional meta information | ||
| if (decorate) { | ||
| this.checksum = hash.MD5(this); | ||
| this.id = uuid.v4(); | ||
| this.timestamp = Date.now(); | ||
| this.stacktrace = stacktrace.parse(this); | ||
| } | ||
| }; | ||
| // easy JSON conversion | ||
| SerialisedError.prototype.toJSON = function () { | ||
| return JSON.stringify(this); | ||
| }; | ||
| module.exports = SerialisedError; |
+6
-1
| { | ||
| "name": "serialised-error", | ||
| "version": "1.0.0", | ||
| "version": "1.1.0", | ||
| "description": "Serialises error object to normal object", | ||
@@ -29,3 +29,8 @@ "main": "index.js", | ||
| "mocha": "^2.2.5" | ||
| }, | ||
| "dependencies": { | ||
| "node-uuid": "^1.4.3", | ||
| "object-hash": "^0.8.0", | ||
| "stack-trace": "0.0.9" | ||
| } | ||
| } |
@@ -22,2 +22,10 @@ var expect = require('expect.js'), | ||
| }); | ||
| it('must add error meta when specified', function () { | ||
| var error = SerialisedError(new Error('Error Name'), true); | ||
| error.extra = 'Extra Property'; | ||
| expect(Object.keys(error)).to.eql(['name', 'message', 'stack', 'checksum', 'id', 'timestamp', 'stacktrace', | ||
| 'extra']); | ||
| }); | ||
| }); |
17206
4.27%45
45.16%3
Infinity%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added