Skip to content

Improve collectDenormalizationErrors #5843

@vincentchalamon

Description

@vincentchalamon

Description

Using collectDenormalizationErrors key converts deserialization exceptions to validation violations. But sometimes, some deserialization exceptions are not catched, which cause an HTTP 400 far before the validation process. It leads to an incomplete response without all the violations.

Example

Request:

POST /bookmarks
Content-Type: application/ld+json
Accept: application/ld+json

{
    "book": "/book/uuid-of-a-non-existing-book",
    "bookmarkedAt": ""
}

400 HTTP Response:

{
    "@context": "/contexts/Error",
    "@type": "hydra:Error",
    "hydra:title": "An error occurred",
    "hydra:description": "Item not found for \"/books/uuid-of-a-non-existing-book\".",
}

Expected response

HTTP 422

{
    "@context": "/contexts/Error",
    "@type": "hydra:Error",
    "hydra:title": "An error occurred",
    "hydra:description": "book: Item not found for \"/books/uuid-of-a-non-existing-book\".\nbookmarkedAt: This value should not be blank.",
    "violations": [
        {
            "propertyPath": "book",
            "hint": "Item not found for \"/books/uuid-of-a-non-existing-book\"."
        },
        {
            "propertyPath": "bookmarkedAt",
            "hint": "This value should not be blank."
        }
    ]
}

Metadata

Metadata

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions