createerror
Advanced tools
Comparing version 0.5.0 to 0.5.1
@@ -41,2 +41,11 @@ (function (root, factory) { | ||
// to avoid doing if (err instanceof NotFound) | ||
// instead you can just do if (err.NotFound) | ||
if (options.name) { | ||
options[options.name] = true; | ||
} | ||
var optionsWithoutData = extend({}, options); | ||
delete optionsWithoutData.data; | ||
function Constructor(messageOrOptionsOrError) { | ||
@@ -62,3 +71,6 @@ var err; | ||
extend(err, options); | ||
extend(err, optionsWithoutData); | ||
if (options.data) { | ||
err.data = extend({}, options.data); | ||
} | ||
if (typeof messageOrOptionsOrError === 'object' && messageOrOptionsOrError) { | ||
@@ -77,7 +89,4 @@ if ('data' in messageOrOptionsOrError) { | ||
// to avoid doing if (err instanceof NotFound) | ||
// instead you can just do if (err.NotFound) | ||
if (options.name) { | ||
Constructor.name = options.name; | ||
options[options.name] = true; | ||
} | ||
@@ -84,0 +93,0 @@ |
@@ -11,3 +11,3 @@ { | ||
], | ||
"version": "0.5.0", | ||
"version": "0.5.1", | ||
"repository": { | ||
@@ -14,0 +14,0 @@ "type": "git", |
@@ -90,2 +90,16 @@ var expect = require('unexpected'), | ||
}); | ||
it('should not share the data object between instances', function () { | ||
var classData = {hey: 'there'}; | ||
var Err = createError({data: classData}), | ||
err1 = new Err(); | ||
expect(err1.data, 'to equal', {hey: 'there'}); | ||
expect(err1.data, 'not to be', classData); | ||
err1.data.foo = 'bar'; | ||
var err2 = new Err(); | ||
expect(err2.data.foo, 'to be undefined'); | ||
}); | ||
}); |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
11253
169
1