failedValidation method

void failedValidation(
  1. Map<String, List<String>> errors
)

Handle validation failure.

This hook is called when validation fails. The default implementation re-throws the ValidationException, but you can override this method to perform additional actions like logging, notifications, or custom error handling before re-throwing.

If you override this method, you should typically call super.failedValidation(errors) to maintain the expected behavior of throwing the exception.

Example:

@override
void failedValidation(Map<String, String> errors) {
  // Log validation failures
  logger.warning('Validation failed for ${request?.uri.path}', {
    'errors': errors,
    'user_id': request?.user()?.id,
    'ip': request?.ip(),
  });

  // Send to monitoring service
  monitoring.track('validation_failed', {
    'field_count': errors.length,
    'request_path': request?.uri.path,
  });

  // Re-throw the exception
  super.failedValidation(errors);
}

Parameters:

  • errors: A map of field names to error messages

Throws: ValidationException (by default implementation)

Implementation

void failedValidation(Map<String, List<String>> errors) {
  throw ValidationException(errors);
}