Socket
Socket
Sign inDemoInstall

createerror

Package Overview
Dependencies
0
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 0.5.0 to 0.5.1

17

lib/createError.js

@@ -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');
});
});
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc