Skip to content

Commit

Permalink
Allow coercion of untyped CuvvaErrors to typed CuvvaErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jFransham authored and billinghamj committed Sep 2, 2015
1 parent ce63154 commit e7c7c60
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
8 changes: 5 additions & 3 deletions lib/cuvva-error.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ function CuvvaError(code, reasons, meta) {
if (!(this instanceof CuvvaError))
return new CuvvaError(code, reasons, meta);

if (!Array.isArray(reasons)) {
if (!meta && !Array.isArray(reasons)) {
meta = reasons;
reasons = void 0;
}
Expand All @@ -24,8 +24,8 @@ function CuvvaError(code, reasons, meta) {
Object.defineProperty(this, 'httpStatus', { get: function () { return statusCode; } });

this.code = code;
this.meta = meta;
this.reasons = reasons;
this.meta = meta;
}

util.inherits(CuvvaError, Error);
Expand All @@ -41,7 +41,9 @@ CuvvaError.coerce = function (error) {

if (error instanceof Error) {
newError = new CuvvaError('unknown', { message: error.message });
Object.defineProperty(newError, 'stack', { get: function () { return error.stack; } });
Object.defineProperty(newError, 'stack', { get: function () { return error.stack } });
} else if (error.code) {
newError = new CuvvaError(error.code, error.reasons, error.meta);
} else {
newError = new CuvvaError('unknown', { error: error });
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cuvva-log",
"version": "0.6.2",
"version": "0.6.3",
"description": "Super simple standardized logging used by all Cuvva systems",
"homepage": "https://github.com/cuvva/cuvva-log-node",
"bugs": "https://github.com/cuvva/cuvva-log-node/issues",
Expand Down

0 comments on commit e7c7c60

Please sign in to comment.