I'm using API Platform in my Symfony application and encountering an issue with the automatic Get() route when searching for a resource that doesn't exist. Currently, API Platform returns a default error response like this:
{
"@id": "/api/errors/404",
"@type": "hydra:Error",
"title": "An error occurred",
"detail": "Not Found",
"status": 404,
"type": "/errors/404",
"trace": [
{
"file": "C:\\wamp64\\www\\repas_siege_api\\vendor\\api-platform\\core\\src\\State\\Provider\\ParameterProvider.php",
"line": 99,
"function": "provide",
"class": "ApiPlatform\\State\\Provider\\ReadProvider",
"type": "->"
},
// more trace details...
]
}
Instead, I'd like to customize this response to something like:
json
{
"error": {
"code": 404,
"message": "Id not found"
}
}
Is there a way to modify or override the default error response format for Get() routes in API Platform when a resource with a specified ID is not found?
I've reviewed the documentation but haven't found a clear solution yet. Any guidance on how to achieve this customization would be greatly appreciated.