Skip to content

Commit 78d24a4

Browse files
committed
feature #6927 Create InvalidEntityException to replace RuntimeException in EntityUpdater (Pierstoval)
This PR was merged into the 4.x branch. Discussion ---------- Create InvalidEntityException to replace RuntimeException in EntityUpdater Why? Because this would allow the EntityUpdater or another layer to catch this exception specifically, in order to handle validation errors differently than what EasyAdmin proposes. This is minor, but it can have a huge impact on what I'm working on :) Commits ------- 446672d Create InvalidEntityException to replace RuntimeException in EntityUpdater
2 parents 740f3d0 + 446672d commit 78d24a4

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
<?php
2+
3+
namespace EasyCorp\Bundle\EasyAdminBundle\Exception;
4+
5+
use Symfony\Component\Validator\ConstraintViolationListInterface;
6+
7+
class InvalidEntityException extends \RuntimeException
8+
{
9+
public function __construct(
10+
public readonly ConstraintViolationListInterface $violations,
11+
) {
12+
parent::__construct((string) $this->violations);
13+
}
14+
}

src/Orm/EntityUpdater.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use EasyCorp\Bundle\EasyAdminBundle\Contracts\Orm\EntityUpdaterInterface;
66
use EasyCorp\Bundle\EasyAdminBundle\Dto\EntityDto;
7+
use EasyCorp\Bundle\EasyAdminBundle\Exception\InvalidEntityException;
78
use Symfony\Component\PropertyAccess\PropertyAccessorInterface;
89
use Symfony\Component\Validator\ConstraintViolationList;
910
use Symfony\Component\Validator\Validator\ValidatorInterface;
@@ -34,7 +35,7 @@ public function updateProperty(EntityDto $entityDto, string $propertyName, $valu
3435
/** @var ConstraintViolationList $violations */
3536
$violations = $this->validator->validate($entityInstance);
3637
if (0 < \count($violations)) {
37-
throw new \RuntimeException((string) $violations);
38+
throw new InvalidEntityException($violations);
3839
}
3940

4041
$entityDto->setInstance($entityInstance);

0 commit comments

Comments
 (0)