Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion src/Exceptions/ValidationException.php
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class ValidationException extends Exception
*/
public function __construct(array $errors)
{
parent::__construct('The given data failed to pass validation.');
parent::__construct($this->resolveMessage($errors));

$this->errors = $errors;
}
Expand All @@ -34,4 +34,19 @@ public function errors()
{
return $this->errors;
}

/**
* Resolve the message based on the provided errors.
*
* @param array $errors An array containing validation errors.
* @return string The resolved message string.
*/
private function resolveMessage(array $errors): string
{
if (empty($errors)) {
return 'The given data failed to pass validation.';
}

return current(current($errors));
}
}