Skip to content

Commit

Permalink
Validation errors now have isValidationError: true
Browse files Browse the repository at this point in the history
  • Loading branch information
notheotherben committed Jan 7, 2014
1 parent 50fccc2 commit 109657c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions lib/utils/validation.js
Expand Up @@ -37,8 +37,15 @@ function validateType(schemaType, value, property, extra) {
got: got
},
toError: function () {
if (this.reason.property) return new Error(String.format('Failed to validate, expected value of {0} to be a {1} but got {2}', this.reason.property, this.reason.expected, this.reason.got || 'nothing'));
return new Error(String.format('Failed to validate, expected {0} but got {1}', this.reason.expected, this.reason.got || 'nothing'));
var error = null;
if (this.reason.property) error = new Error(String.format('Failed to validate, expected value of {0} to be a {1} but got {2}', this.reason.property, this.reason.expected, this.reason.got || 'nothing'));
else error = Error(String.format('Failed to validate, expected {0} but got {1}', this.reason.expected, this.reason.got || 'nothing'));

error.isValidationError = true;
error.property = this.reason.property;
error.expected = this.reason.expected;
error.got = this.reason.got;
return error;
}
};
};
Expand Down

0 comments on commit 109657c

Please sign in to comment.