Comparing version 1.0.0 to 1.1.0
20
index.js
'use strict'; | ||
var has = Object.prototype.hasOwnProperty; | ||
/** | ||
@@ -13,8 +15,14 @@ * Return an object with all the information that should be in the JSON output. | ||
function toJSON() { | ||
return { | ||
statusCode: this.statusCode, | ||
message: this.message, | ||
stack: this.stack, | ||
type: this.type | ||
}; | ||
var obj = { message: this.message, stack: this.stack }, key; | ||
for (key in this) { | ||
if ( | ||
has.call(this, key) | ||
&& 'function' !== typeof this[key] | ||
) { | ||
obj[key] = this[key]; | ||
} | ||
} | ||
return obj; | ||
} | ||
@@ -21,0 +29,0 @@ |
{ | ||
"name": "failure", | ||
"version": "1.0.0", | ||
"version": "1.1.0", | ||
"description": "Easily generate \"custom\" error objects with addition properties which can be stringfied with JSON.stringify", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
14
test.js
@@ -43,3 +43,3 @@ describe('failure', function () { | ||
assume(err.what).equals('why'); | ||
assume(res.what).is.undefined(); | ||
assume(res.what).is.equals('why'); | ||
assume(res.statusCode).equals(200); | ||
@@ -49,2 +49,14 @@ assume(err.statusCode).equals(200); | ||
it('includes properties that were previously specified on a given error', function () { | ||
var err = new Error('fools') | ||
, res; | ||
err.warning = true; | ||
res = failure(err, { what: 'lol' }).toJSON(); | ||
assume(res.what).equals('lol'); | ||
assume(res.warning).equals(true); | ||
assume(res.message).equals('fools'); | ||
}); | ||
it('does not override existing toJSON functions', function () { | ||
@@ -51,0 +63,0 @@ var err = new Error('lol'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
9297
99