Skip to content

Commit 8b051a6

Browse files
committed
fix(serializer): throw NotNormalizableValueException when resource not found or invalid IRI on denormalization
1 parent 7c52f34 commit 8b051a6

File tree

1 file changed

+26
-2
lines changed

1 file changed

+26
-2
lines changed

src/Serializer/AbstractItemNormalizer.php

+26-2
Original file line numberDiff line numberDiff line change
@@ -243,9 +243,33 @@ public function denormalize(mixed $data, string $class, ?string $format = null,
243243
try {
244244
return $this->iriConverter->getResourceFromIri($data, $context + ['fetch_data' => true]);
245245
} catch (ItemNotFoundException $e) {
246-
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
246+
if (!isset($context['not_normalizable_value_exceptions'])) {
247+
throw new UnexpectedValueException($e->getMessage(), $e->getCode(), $e);
248+
}
249+
250+
throw NotNormalizableValueException::createForUnexpectedDataType(
251+
\sprintf('The type of the "%s" resource "string" (IRI), "%s" given.', $resourceClass, \gettype($data)),
252+
$data,
253+
[$resourceClass],
254+
$context['deserialization_path'] ?? null,
255+
true,
256+
$e->getCode(),
257+
$e
258+
);
247259
} catch (InvalidArgumentException $e) {
248-
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
260+
if (!isset($context['not_normalizable_value_exceptions'])) {
261+
throw new UnexpectedValueException(\sprintf('Invalid IRI "%s".', $data), $e->getCode(), $e);
262+
}
263+
264+
throw NotNormalizableValueException::createForUnexpectedDataType(
265+
\sprintf('The type of the "%s" resource "string" (IRI), "%s" given.', $resourceClass, \gettype($data)),
266+
$data,
267+
[$resourceClass],
268+
$context['deserialization_path'] ?? null,
269+
true,
270+
$e->getCode(),
271+
$e
272+
);
249273
}
250274
}
251275

0 commit comments

Comments
 (0)