You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
new ValidationError(errors: Array, [message: String])
errors must be an array with keys of the form:
[{// Name of the field this error is about.name: String,// Type of error, can be mapped to a nice message on the client.type: String,// Any kind of details that depends on the type of error can be added as// an extra object's property (eg. `message` with a per field error message// or `value` that contains the invalid value passed from the client).
...
}
...
]
message is an optional string to use for the error message so that the text printed at the top of the stack trace when the error is thrown is more useful. For example, if you pass in the error {name: 'name', type: 'required'}, you may want to also pass in the message "Name is required".
ValidationError.is(error: Meteor.Error)
The static ValidationError.is method is a helper for checking if an error thrown by a server and catched on the client is an instance of ValidationError.
// Inside a method definitionsaveProduct({ name, cost, category }){if(cost>1000){thrownewValidationError([{name: 'cost',type: 'out-of-range',value: cost,min: 0,max: 100}]);}// ... the rest of the method}
You might catch the error returned by a method call and display it in the UI:
This type of error is automatically thrown for invalid arguments if you use the mdg:validated-method package, where you can specify a schema for the arguments of your method.