validateEvent function
HookedServiceEventListener<dynamic, dynamic, Service<Never, Never> >
validateEvent(})
Validates the data in e.data
, and sets the data to
filtered data before continuing the service event.
Implementation
HookedServiceEventListener validateEvent(Validator validator,
{String errorMessage = 'Invalid data.'}) {
return (HookedServiceEvent e) async {
var app = e.request?.app ?? e.service.app;
var result = await asyncApplyValidator(validator, e.data as Map, app);
if (result.errors.isNotEmpty) {
throw AngelHttpException.badRequest(
message: errorMessage, errors: result.errors);
}
e.data
..clear()
..addAll(result.data);
};
}