api-platform / core

The server component of API Platform: hypermedia and GraphQL APIs in minutes
https://api-platform.com
MIT License
2.45k stars 878 forks source link

The root cause of the deserialization error remain hidden on API output #6725

Open cay89 opened 1 month ago

cay89 commented 1 month ago

API Platform version(s) affected: 4.0.4

Description
If \ApiPlatform\State\Provider\DeserializeProvider::provide() throws an error, I only get the message "An error occurred" alongside the "trace", but it doesn't specify what the actual issue is.

If I catch it here and print it out, it turns out that the message is "Update is not allowed for this operation."

\ApiPlatform\State\Provider\DeserializeProvider image

How to reproduce
Throw an exception in \ApiPlatform\State\Provider\DeserializeProvider::provide().

Possible Solution
Add #[Groups(['jsonld', 'jsonproblem', 'jsonapi'])] attribute to ApiResource/Error::getDescription() method.

ApiResource/Error

#[SerializedName('description')]
#[Groups(['jsonld', 'jsonproblem', 'jsonapi'])]
public function getDescription(): string
{
    return $this->detail;
}

Result:

image

soyuka commented 1 month ago

description is only for JSON-LD, detail should always be available though.