Comparing version 7.0.2 to 7.1.0
{ | ||
"name": "error", | ||
"version": "7.0.2", | ||
"version": "7.1.0", | ||
"description": "Custom errors", | ||
@@ -20,4 +20,3 @@ "keywords": [], | ||
"dependencies": { | ||
"string-template": "~0.2.1", | ||
"xtend": "~4.0.0" | ||
"string-template": "~0.2.1" | ||
}, | ||
@@ -24,0 +23,0 @@ "devDependencies": { |
@@ -24,2 +24,4 @@ 'use strict'; | ||
assert.equal(error.message, 'some title server error, status=500'); | ||
assert.equal(error.toString(), | ||
'Server5xxErrorError: some title server error, status=500') | ||
@@ -44,4 +46,6 @@ assert.end(); | ||
assert.equal(error2.message, 'some title client error, status=404'); | ||
assert.equal(error2.toString(), | ||
'Client4xxErrorError: some title client error, status=404') | ||
assert.end(); | ||
}); |
@@ -38,6 +38,6 @@ 'use strict'; | ||
type: 'server.listen-failed', | ||
name: 'ServerListenFailedError', | ||
message: 'server: listen EADDRINUSE', | ||
requestedPort: 3426, | ||
host: 'localhost', | ||
name: 'ServerListenFailedError', | ||
causeMessage: 'listen EADDRINUSE', | ||
@@ -156,3 +156,4 @@ origMessage: 'listen EADDRINUSE', | ||
function assertOnError(err, cause, port) { | ||
assert.equal(err.message, 'server: listen EADDRINUSE'); | ||
assert.ok(err.message.indexOf('server: ') >= 0) | ||
assert.ok(err.message.indexOf('listen EADDRINUSE') >= 0) | ||
assert.equal(err.requestedPort, port); | ||
@@ -164,13 +165,20 @@ assert.equal(err.host, 'localhost'); | ||
assert.equal(err.toString(), | ||
'ServerListenFailedError: server: listen EADDRINUSE'); | ||
assert.ok(err.toString().indexOf('ServerListenFailedError: ') >= 0) | ||
assert.ok(err.toString().indexOf('server: ') >= 0) | ||
assert.ok(err.toString().indexOf('listen EADDRINUSE') >= 0) | ||
var expectedMessage = err.message | ||
var expectedOrigMessage = err.origMessage | ||
assert.ok(err.origMessage.indexOf('listen EADDRINUSE') >= 0) | ||
assert.ok(err.origMessage.indexOf('server: ') === -1) | ||
assert.equal(JSON.stringify(err), JSON.stringify({ | ||
type: 'server.listen-failed', | ||
message: 'server: listen EADDRINUSE', | ||
name: 'ServerListenFailedError', | ||
message: expectedMessage, | ||
requestedPort: port, | ||
host: 'localhost', | ||
name: 'ServerListenFailedError', | ||
causeMessage: 'listen EADDRINUSE', | ||
origMessage: 'listen EADDRINUSE', | ||
causeMessage: expectedOrigMessage, | ||
origMessage: expectedOrigMessage, | ||
code: 'EADDRINUSE', | ||
@@ -186,1 +194,16 @@ errno: 'EADDRINUSE', | ||
}); | ||
test('can wrap assert errors', function t(assert) { | ||
var TestError = WrappedError({ | ||
message: 'error: {origMessage}', | ||
type: 'error' | ||
}); | ||
var assertError; | ||
try { require('assert').equal('a', 'b'); } | ||
catch (_err) { assertError = _err; } | ||
var err = TestError(assertError); | ||
assert.equal(err.cause.actual, 'a'); | ||
assert.end(); | ||
}) |
24
typed.js
'use strict'; | ||
var template = require('string-template'); | ||
var extend = require('xtend/mutable'); | ||
var assert = require('assert'); | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
var isWordBoundary = /[_.-](\w|$)/g; | ||
@@ -20,9 +20,12 @@ | ||
var message = args.message; | ||
if (args.type && !args.name) { | ||
var funcName = args.name | ||
if (!funcName) { | ||
var errorName = camelCase(args.type) + 'Error'; | ||
args.name = errorName[0].toUpperCase() + errorName.substr(1); | ||
funcName = errorName[0].toUpperCase() + errorName.substr(1); | ||
} else { | ||
delete args.name | ||
} | ||
extend(createError, args); | ||
createError._name = args.name; | ||
createError._name = funcName; | ||
@@ -41,3 +44,5 @@ return createError; | ||
var options = extend({}, args, opts); | ||
var options = {} | ||
extend(options, args) | ||
extend(options, opts) | ||
if (!options.fullType) { | ||
@@ -47,2 +52,3 @@ options.fullType = options.type; | ||
result.name = funcName | ||
extend(result, options); | ||
@@ -59,2 +65,10 @@ if (opts && opts.message) { | ||
function extend(target, source) { | ||
for (var key in source) { | ||
if (hasOwnProperty.call(source, key)) { | ||
target[key] = source[key] | ||
} | ||
} | ||
} | ||
function camelCase(str) { | ||
@@ -61,0 +75,0 @@ return str.replace(isWordBoundary, upperCase); |
'use strict'; | ||
var extend = require('xtend/mutable'); | ||
var assert = require('assert'); | ||
var util = require('util'); | ||
@@ -12,2 +12,3 @@ var TypedError = require('./typed.js'); | ||
var origMessageRegex = /\{origMessage\}/g; | ||
var hasOwnProperty = Object.prototype.hasOwnProperty; | ||
@@ -58,3 +59,5 @@ module.exports = WrappedError; | ||
var nodeCause = false; | ||
var errOptions = extend({}, opts, { | ||
var errOptions = {} | ||
extend(errOptions, opts) | ||
extend(errOptions, { | ||
causeMessage: causeMessage, | ||
@@ -106,3 +109,11 @@ origMessage: causeMessage | ||
function isError(err) { | ||
return objectToString.call(err) === ERROR_TYPE; | ||
return util.isError(err) || objectToString.call(err) === ERROR_TYPE; | ||
} | ||
function extend(target, source) { | ||
for (var key in source) { | ||
if (hasOwnProperty.call(source, key)) { | ||
target[key] = source[key] | ||
} | ||
} | ||
} |
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
19181
1
407
13
- Removedxtend@~4.0.0
- Removedxtend@4.0.2(transitive)