Skip to content

Transform ItemNotFoundException to constraint violation #5521

@ihmels

Description

@ihmels

If a dereferenceable IRI is used in a request and no resource exists under this IRI, an
ItemNotFoundException is thrown, which results in a response with status code 500 with the
following content:

{
  "@context": "/api/contexts/Error",
  "@type": "hydra:Error",
  "hydra:title": "An error occurred",
  "hydra:description": "Internal Server Error"
}

The content of the request was:

{
  "product": "/api/products/not_existing"
}

This response is not very helpful for the user of the API. Therefore it would be better if such an
error could be converted into a validation error:

{
  "@context": "/api/contexts/ConstraintViolationList",
  "@type": "ConstraintViolationList",
  "hydra:title": "An error occurred",
  "hydra:description": "product: Item not found for \"/api/products/not_existing\".",
  "violations": [
    {
      "propertyPath": "product",
      "message": "Item not found for \"/api/products/not_existing\".",
      "code": null
    }
  ]
}

For this, we could use the mechanism by which type errors are collected during denormalization
(PartialDenormalizationException).

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions