diff --git a/src/Symfony/Bundle/DependencyInjection/Configuration.php b/src/Symfony/Bundle/DependencyInjection/Configuration.php index fb070df050..e7f3b7cb68 100644 --- a/src/Symfony/Bundle/DependencyInjection/Configuration.php +++ b/src/Symfony/Bundle/DependencyInjection/Configuration.php @@ -23,6 +23,7 @@ use Doctrine\Bundle\DoctrineBundle\DoctrineBundle; use Doctrine\Bundle\MongoDBBundle\DoctrineMongoDBBundle; use Doctrine\ORM\EntityManagerInterface; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\ORM\OptimisticLockException; use GraphQL\GraphQL; @@ -594,6 +595,7 @@ private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode): voi InvalidArgumentException::class => Response::HTTP_BAD_REQUEST, OptimisticLockException::class => Response::HTTP_CONFLICT, UniqueConstraintViolationException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ForeignKeyConstraintViolationException::class => Response::HTTP_CONFLICT, ]) ->info('The list of exceptions mapped to their HTTP status code.') ->normalizeKeys(false) diff --git a/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php b/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php index b1d0a51c44..3c17a87a14 100644 --- a/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php +++ b/tests/Symfony/Bundle/DependencyInjection/ConfigurationTest.php @@ -15,6 +15,7 @@ use ApiPlatform\Metadata\Exception\InvalidArgumentException; use ApiPlatform\Symfony\Bundle\DependencyInjection\Configuration; +use Doctrine\DBAL\Exception\ForeignKeyConstraintViolationException; use Doctrine\DBAL\Exception\UniqueConstraintViolationException; use Doctrine\ORM\OptimisticLockException; use PHPUnit\Framework\Attributes\DataProvider; @@ -103,6 +104,7 @@ private function runDefaultConfigTests(array $doctrineIntegrationsToLoad = ['orm InvalidArgumentException::class => Response::HTTP_BAD_REQUEST, OptimisticLockException::class => Response::HTTP_CONFLICT, UniqueConstraintViolationException::class => Response::HTTP_UNPROCESSABLE_ENTITY, + ForeignKeyConstraintViolationException::class => Response::HTTP_CONFLICT, ], 'path_segment_name_generator' => 'api_platform.metadata.path_segment_name_generator.underscore', 'inflector' => 'api_platform.metadata.inflector',