Comparing version 2.1.0 to 2.2.0
@@ -76,7 +76,9 @@ 'use strict'; | ||
_this.code = code; | ||
// $FlowFixMe | ||
_this.severity = severity; | ||
// $FlowFixMe | ||
_this.message = message; | ||
_this.meta = _extends({}, meta); | ||
if (typeof code !== 'undefined') { | ||
if (code) { | ||
_this.name = createErrorName(code); | ||
@@ -87,3 +89,5 @@ } else { | ||
if (typeof stack === 'undefined') { | ||
if (stack) { | ||
_this.stack = stack; | ||
} else { | ||
var fake = new Error(message); | ||
@@ -94,4 +98,2 @@ fake.name = _this.name; | ||
_this.stack = buildStack.join('\n'); | ||
} else { | ||
_this.stack = stack; | ||
} | ||
@@ -98,0 +100,0 @@ return _this; |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.default = wrap; | ||
exports.default = convert; | ||
@@ -15,3 +15,3 @@ var _Bugsy = require('./Bugsy'); | ||
function wrap(err) { | ||
function convert(err) { | ||
if (err instanceof _Bugsy2.default) { | ||
@@ -22,3 +22,2 @@ return err; | ||
return new _Bugsy2.default({ | ||
code: err.code, | ||
message: err.message, | ||
@@ -25,0 +24,0 @@ stack: err.stack |
@@ -6,3 +6,3 @@ 'use strict'; | ||
}); | ||
exports.syslog = exports.convert = exports.createError = exports.toString = exports.Bugsy = undefined; | ||
exports.syslog = exports.convert = exports.createError = exports.createDynamicError = exports.toString = exports.Bugsy = undefined; | ||
@@ -27,2 +27,11 @@ var _Bugsy = require('./Bugsy'); | ||
var _createDynamicError = require('./createDynamicError'); | ||
Object.defineProperty(exports, 'createDynamicError', { | ||
enumerable: true, | ||
get: function get() { | ||
return _interopRequireDefault(_createDynamicError).default; | ||
} | ||
}); | ||
var _createError = require('./createError'); | ||
@@ -29,0 +38,0 @@ |
@@ -8,2 +8,6 @@ 'use strict'; | ||
var _Bugsy = require('./Bugsy'); | ||
var _Bugsy2 = _interopRequireDefault(_Bugsy); | ||
var _syslog = require('./syslog'); | ||
@@ -15,2 +19,4 @@ | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
function toString(err) { | ||
@@ -21,6 +27,15 @@ var _ref = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}, | ||
var severity = err.severity || syslog.ERROR; | ||
var message = err.message; | ||
var code = err.code || err.name || 'Error'; | ||
var severity = void 0; | ||
var name = void 0; | ||
if (err instanceof _Bugsy2.default) { | ||
severity = err.severity; | ||
name = err.code || err.name; | ||
} else { | ||
severity = syslog.ERROR; | ||
name = err.name; | ||
} | ||
var chunks = []; | ||
@@ -31,3 +46,3 @@ if (withDate) { | ||
chunks.push('[' + severity + ']'); | ||
chunks.push('' + code); | ||
chunks.push('' + name); | ||
if (message) { | ||
@@ -34,0 +49,0 @@ chunks.push(message); |
{ | ||
"name": "bugsy", | ||
"version": "2.1.0", | ||
"version": "2.2.0", | ||
"description": "Helper to deal with errors lifecycle in javascript", | ||
@@ -48,3 +48,3 @@ "author": "Nicolas Jakob <nicow.jakob@gmail.com>", | ||
"devDependencies": { | ||
"ava": "^0.17.0", | ||
"ava": "^0.18.1", | ||
"babel-cli": "^6.18.0", | ||
@@ -51,0 +51,0 @@ "babel-core": "^6.21.0", |
@@ -33,3 +33,3 @@ | ||
```js | ||
```javascript | ||
import * as bugsy from 'bugsy'; | ||
@@ -40,12 +40,12 @@ | ||
const ranAway = bugsy.createError(RAN_AWAY, 'It ran away, again'); | ||
const ranAway = bugsy.createDynamicError(RAN_AWAY, (name) => `${name} ran away, again`); | ||
const throwMissed = bugsy.createError(THROW_MISSED, 'Throw totally missed'); | ||
function capture() { | ||
function capture(name) { | ||
const r = Math.random(); | ||
if (r < 0.3) { | ||
throw throwMissed({ severity: bugsy.syslog.WARNING }); | ||
throw throwMissed(); | ||
} else if (r < 0.6) { | ||
throw ranAway(); | ||
throw ranAway(name); | ||
} else { | ||
@@ -66,3 +66,3 @@ throw new Error(); | ||
try { | ||
capture(); | ||
capture('Abra'); | ||
} catch (err) { | ||
@@ -69,0 +69,0 @@ switch (err.code) { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
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
146943
21
271