Skip to content

Commit 0e712d9

Browse files
authored
fix(symfony): catch InvalidUriVariableException in IriConverter (#7271)
1 parent e40bb19 commit 0e712d9

File tree

3 files changed

+5
-2
lines changed

3 files changed

+5
-2
lines changed

src/Metadata/UriVariablesConverterInterface.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
namespace ApiPlatform\Metadata;
1515

1616
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
17+
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
1718

1819
/**
1920
* Identifier converter.
@@ -29,6 +30,7 @@ interface UriVariablesConverterInterface
2930
* @param string $class The class to which the URI variables belong to
3031
*
3132
* @throws InvalidIdentifierException
33+
* @throws InvalidUriVariableException
3234
*
3335
* @return array Array indexed by identifiers properties with their values denormalized
3436
*/

src/Symfony/Routing/IriConverter.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
use ApiPlatform\Metadata\CollectionOperationInterface;
1717
use ApiPlatform\Metadata\Exception\InvalidArgumentException;
1818
use ApiPlatform\Metadata\Exception\InvalidIdentifierException;
19+
use ApiPlatform\Metadata\Exception\InvalidUriVariableException;
1920
use ApiPlatform\Metadata\Exception\ItemNotFoundException;
2021
use ApiPlatform\Metadata\Exception\OperationNotFoundException;
2122
use ApiPlatform\Metadata\Exception\RuntimeException;
@@ -99,7 +100,7 @@ public function getResourceFromIri(string $iri, array $context = [], ?Operation
99100

100101
try {
101102
$uriVariables = $this->getOperationUriVariables($operation, $parameters, $attributes['resource_class']);
102-
} catch (InvalidIdentifierException $e) {
103+
} catch (InvalidIdentifierException|InvalidUriVariableException $e) {
103104
throw new InvalidArgumentException($e->getMessage(), $e->getCode(), $e);
104105
}
105106

tests/Functional/Issues/Issue7135Test.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ public function testInvalidPostRequestWithIriWhenIdentifierIsUuid(): void
7070
]);
7171

7272
self::assertEquals(400, $response->getStatusCode());
73-
self::assertJsonContains(['detail' => 'Identifier "id" could not be transformed.']);
73+
self::assertJsonContains(['detail' => 'Invalid IRI "pull-request-7135/bar/invalid-uuid".']);
7474
}
7575

7676
public function testInvalidGetRequestWhenIdentifierIsUuid(): void

0 commit comments

Comments
 (0)