Skip to content

Commit bbc9039

Browse files
committed
map OptimisticLockException to HTTP_CONFLICT
1 parent 163cc31 commit bbc9039

File tree

3 files changed

+6
-0
lines changed

3 files changed

+6
-0
lines changed

src/Bridge/Symfony/Bundle/DependencyInjection/Configuration.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515

1616
use ApiPlatform\Core\Exception\FilterValidationException;
1717
use ApiPlatform\Core\Exception\InvalidArgumentException;
18+
use Doctrine\ORM\OptimisticLockException;
1819
use FOS\UserBundle\FOSUserBundle;
1920
use GraphQL\GraphQL;
2021
use Symfony\Bundle\TwigBundle\TwigBundle;
@@ -263,6 +264,7 @@ private function addExceptionToStatusSection(ArrayNodeDefinition $rootNode)
263264
ExceptionInterface::class => Response::HTTP_BAD_REQUEST,
264265
InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
265266
FilterValidationException::class => Response::HTTP_BAD_REQUEST,
267+
OptimisticLockException::class => Response::HTTP_CONFLICT,
266268
])
267269
->info('The list of exceptions mapped to their HTTP status code.')
268270
->normalizeKeys(false)

tests/Bridge/Symfony/Bundle/DependencyInjection/ApiPlatformExtensionTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@
4040
use ApiPlatform\Core\Tests\Fixtures\TestBundle\TestBundle;
4141
use ApiPlatform\Core\Validator\ValidatorInterface;
4242
use Doctrine\Bundle\DoctrineBundle\DoctrineBundle;
43+
use Doctrine\ORM\OptimisticLockException;
4344
use FOS\UserBundle\FOSUserBundle;
4445
use Nelmio\ApiDocBundle\NelmioApiDocBundle;
4546
use PHPUnit\Framework\TestCase;
@@ -487,6 +488,7 @@ private function getPartialContainerBuilderProphecy($test = false)
487488
ExceptionInterface::class => Response::HTTP_BAD_REQUEST,
488489
InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
489490
FilterValidationException::class => Response::HTTP_BAD_REQUEST,
491+
OptimisticLockException::class => Response::HTTP_CONFLICT,
490492
],
491493
'api_platform.title' => 'title',
492494
'api_platform.version' => 'version',

tests/Bridge/Symfony/Bundle/DependencyInjection/ConfigurationTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Bridge\Symfony\Bundle\DependencyInjection\Configuration;
1717
use ApiPlatform\Core\Exception\FilterValidationException;
1818
use ApiPlatform\Core\Exception\InvalidArgumentException;
19+
use Doctrine\ORM\OptimisticLockException;
1920
use PHPUnit\Framework\TestCase;
2021
use Symfony\Component\Config\Definition\Builder\TreeBuilder;
2122
use Symfony\Component\Config\Definition\ConfigurationInterface;
@@ -72,6 +73,7 @@ public function testDefaultConfig()
7273
ExceptionInterface::class => Response::HTTP_BAD_REQUEST,
7374
InvalidArgumentException::class => Response::HTTP_BAD_REQUEST,
7475
FilterValidationException::class => Response::HTTP_BAD_REQUEST,
76+
OptimisticLockException::class => Response::HTTP_CONFLICT,
7577
],
7678
'default_operation_path_resolver' => 'api_platform.operation_path_resolver.underscore',
7779
'path_segment_name_generator' => 'api_platform.path_segment_name_generator.underscore',

0 commit comments

Comments
 (0)