Skip to content

Commit

Permalink
Merge pull request #152 from strongloop/fix-validation-error-stack-in…
Browse files Browse the repository at this point in the history
…-browsers

[2.0] validations: support non-V8 browsers
  • Loading branch information
bajtos committed Jun 24, 2014
2 parents ce82541 + 3572ecd commit 89fbf16
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/validations.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,11 +703,21 @@ function ValidationError(obj) {
messages: obj.errors
};

Error.captureStackTrace(this, this.constructor);
if (Error.captureStackTrace) {
// V8 (Chrome, Opera, Node)
Error.captureStackTrace(this, this.constructor);
} else if (errorHasStackProperty) {
// Firefox
this.stack = (new Error).stack;
}
// Safari and PhantomJS initializes `error.stack` on throw
// Internet Explorer does not support `error.stack`
}

util.inherits(ValidationError, Error);

var errorHasStackProperty = !!(new Error).stack;

function formatErrors(errors) {
var DELIM = '; ';
errors = errors || {};
Expand Down

0 comments on commit 89fbf16

Please sign in to comment.