Skip to content

Commit

Permalink
Merge pull request #31 from Toflar/patch-1
Browse files Browse the repository at this point in the history
Catch exceptions in validator
  • Loading branch information
ddebowczyk authored Sep 30, 2024
2 parents fc55b5f + 11410a9 commit f80bcff
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/Validation/Validators/SymfonyValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@ public function validate(object $dataObject) : ValidationResult {
->addLoader(new AttributeLoader())
->getValidator();

$result = $validator->validate($dataObject);

try {
$result = $validator->validate($dataObject);
} catch (\Exception $e) {
return ValidationResult::make($errors, $e->getMessage());
}

$errors = [];
foreach ($result as $error) {
$path = $error->getPropertyPath();
Expand All @@ -26,4 +30,4 @@ public function validate(object $dataObject) : ValidationResult {

return ValidationResult::make($errors, 'Validation failed');
}
}
}

0 comments on commit f80bcff

Please sign in to comment.