Skip to content

Commit fbf69f0

Browse files
committed
Update thrown exception and clarify error message.
As discussed in issue #3045, the given error message was misleading. I also updated the thrown exception according to the Exception mentioned in the same issue. Of course I updated the related PHPUnit test too.
1 parent b5e933e commit fbf69f0

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

src/Bridge/RamseyUuid/Identifier/Normalizer/UuidNormalizer.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@
1313

1414
namespace ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer;
1515

16-
use ApiPlatform\Core\Exception\InvalidIdentifierException;
1716
use Ramsey\Uuid\Exception\InvalidUuidStringException;
1817
use Ramsey\Uuid\Uuid;
1918
use Ramsey\Uuid\UuidInterface;
19+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
2020
use Symfony\Component\Serializer\Normalizer\DenormalizerInterface;
2121

2222
/**
@@ -28,20 +28,22 @@ final class UuidNormalizer implements DenormalizerInterface
2828
{
2929
/**
3030
* {@inheritdoc}
31+
*
32+
* @throws NotNormalizableValueException Occurs when the identifier format is invalid
3133
*/
3234
public function denormalize($data, $class, $format = null, array $context = [])
3335
{
3436
try {
3537
return Uuid::fromString($data);
3638
} catch (InvalidUuidStringException $e) {
37-
throw new InvalidIdentifierException($e->getMessage(), $e->getCode(), $e);
39+
throw new NotNormalizableValueException('Not found, because of an invalid identifier format', $e->getCode(), $e);
3840
}
3941
}
4042

4143
/**
4244
* {@inheritdoc}
4345
*/
44-
public function supportsDenormalization($data, $type, $format = null)
46+
public function supportsDenormalization($data, $type, $format = null): bool
4547
{
4648
return is_a($type, UuidInterface::class, true);
4749
}

tests/Bridge/RamseyUuid/Normalizer/UuidNormalizerTest.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Core\Bridge\RamseyUuid\Identifier\Normalizer\UuidNormalizer;
1717
use PHPUnit\Framework\TestCase;
1818
use Ramsey\Uuid\Uuid;
19+
use Symfony\Component\Serializer\Exception\NotNormalizableValueException;
1920

2021
class UuidNormalizerTest extends TestCase
2122
{
@@ -36,7 +37,7 @@ public function testNoSupportDenormalizeUuid()
3637

3738
public function testFailDenormalizeUuid()
3839
{
39-
$this->expectException(\ApiPlatform\Core\Exception\InvalidIdentifierException::class);
40+
$this->expectException(NotNormalizableValueException::class);
4041

4142
$uuid = 'notanuuid';
4243
$normalizer = new UuidNormalizer();

0 commit comments

Comments
 (0)