Skip to content

[question]: How to catch exceptions and return proper messages (Problem Details) #316

@todor-programista

Description

@todor-programista

Hey guys,

I need to catch some exceptions and return proper ProblemDetails response.
For example:
curl -X DELETE --header 'Accept: application/problem+json' 'https://demo.api-platform.com/books/6'

returns:

Status: 500
{
  "type": "https://tools.ietf.org/html/rfc2616#section-10",
  "title": "An error occurred",
  "detail": "Internal Server Error"
}

which based on my case I presume is because of the foreign key constraint for the relation to 'Reviews'

In the logs there is an PDO exception that I need to catch and return 409 Conflict for example (or somethign else)

How do I hook to the flow and return ApiProblemResponse?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions