core
core copied to clipboard
When State Provider returns null a 500 error is returned due to rfc_7807_compliant_errors=true
API Platform version(s) affected: 3.2.13 (symfony v6.4.3)
Description
I have a custom State Provider and if it returns null for a resource that does not exist, instead of getting a clear 404 response, api-platform throws an Error with a 500 response. The error says:
Unable to generate an IRI for the item of type "ApiPlatform\State\ApiResource\Error"
This only occurs when rfc_7807_compliant_errors is set to true (and is recommended according to the docs).
How to reproduce
set rfc_7807_compliant_errors to true in config.
api_platform:
defaults:
extra_properties:
rfc_7807_compliant_errors: true
Create a State provider that returns a null value from provide.
class MyProvider implements ProviderInterface
{
public function provide(Operation $operation, array $uriVariables = [], array $context = []): object|array|null
{
return null;
}
}
Possible Solution
Additional Context