diff options
Diffstat (limited to 'services/app/src/Exceptions/EntityValidationException.php')
| -rw-r--r-- | services/app/src/Exceptions/EntityValidationException.php | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/services/app/src/Exceptions/EntityValidationException.php b/services/app/src/Exceptions/EntityValidationException.php new file mode 100644 index 0000000..d4d958e --- /dev/null +++ b/services/app/src/Exceptions/EntityValidationException.php @@ -0,0 +1,35 @@ +<?php + +declare(strict_types=1); + +namespace Nsfisis\Albatross\Exceptions; + +use RuntimeException; +use Throwable; + +final class EntityValidationException extends RuntimeException +{ + /** + * @param array<string, string> $errors + */ + public function __construct( + string $message = '', + int $code = 0, + ?Throwable $previous = null, + private readonly array $errors = [], + ) { + parent::__construct($message, $code, $previous); + } + + /** + * @return array<string, string> + */ + public function toFormErrors(): array + { + if (count($this->errors) === 0) { + return ['general' => $this->getMessage()]; + } else { + return $this->errors; + } + } +} |
