Skip to content

Commit 072c18e

Browse files
committed
ISSUE-345: return 400 on validation exception
1 parent 3786974 commit 072c18e

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

src/Common/EventListener/ExceptionListener.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Symfony\Component\HttpKernel\Event\ExceptionEvent;
1111
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
1212
use Symfony\Component\HttpKernel\Exception\HttpExceptionInterface;
13+
use Symfony\Component\Validator\Exception\ValidatorException;
1314

1415
class ExceptionListener
1516
{
@@ -34,6 +35,11 @@ public function onKernelException(ExceptionEvent $event): void
3435
'message' => $exception->getMessage(),
3536
], $exception->getStatusCode());
3637
$event->setResponse($response);
38+
} elseif ($exception instanceof ValidatorException) {
39+
$response = new JsonResponse([
40+
'message' => $exception->getMessage(),
41+
], 400);
42+
$event->setResponse($response);
3743
} elseif ($exception instanceof Exception) {
3844
$response = new JsonResponse([
3945
'message' => $exception->getMessage(),

tests/Integration/Identity/Controller/AdminAttributeDefinitionControllerTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public function testCreateAttributeDefinitionWithValidDataReturnsCreated(): void
3131
{
3232
$this->authenticatedJsonRequest('post', '/api/v2/administrators/attributes', [], [], [], json_encode([
3333
'name' => 'Test Attribute',
34-
'type' => 'text',
34+
'type' => 'textarea',
3535
'order' => 1,
3636
'defaultValue' => 'default',
3737
'required' => true,
@@ -41,7 +41,7 @@ public function testCreateAttributeDefinitionWithValidDataReturnsCreated(): void
4141
$this->assertHttpCreated();
4242
$data = $this->getDecodedJsonResponseContent();
4343
self::assertSame('Test Attribute', $data['name']);
44-
self::assertSame('text', $data['type']);
44+
self::assertSame('textarea', $data['type']);
4545
self::assertSame(1, $data['list_order']);
4646
self::assertSame('default', $data['default_value']);
4747
self::assertTrue($data['required']);

0 commit comments

Comments
 (0)