Skip to content

Commit b559bc0

Browse files
committed
Better Match error (closes #333)
1 parent 9f5262f commit b559bc0

File tree

1 file changed

+9
-2
lines changed

1 file changed

+9
-2
lines changed

simple-schema.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,15 @@ SimpleSchema.prototype.condition = function(obj) {
596596
throw new Match.Error("Object cannot contain modifier operators alongside other keys");
597597
}
598598

599-
if (!self.newContext().validate(obj, {modifier: isModifier, filter: false, autoConvert: false})) {
600-
throw new Match.Error("One or more properties do not match the schema.");
599+
var ctx = self.newContext();
600+
if (!ctx.validate(obj, {modifier: isModifier, filter: false, autoConvert: false})) {
601+
var error = ctx.getErrorObject();
602+
var matchError = new Match.Error(error.message);
603+
matchError.invalidKeys = error.invalidKeys;
604+
if (Meteor.isServer) {
605+
matchError.sanitizedError = error.sanitizedError;
606+
}
607+
throw matchError;
601608
}
602609

603610
return true;

0 commit comments

Comments
 (0)