Skip to content

Customize Doctrine Exception Message #973

Description

@jsamouh

Hello,
I was working on configuration of status code for exception.

For the moment, I define this in config yml file:
exception_to_status:
ApiPlatform\Core\Exception\InvalidArgumentException: 400
Doctrine\DBAL\Exception\UniqueConstraintViolationException: 409

For the first exception, the message return is correct and I do not need to modify it
(Ex: The type of the "my_field" attribute must be "int", "double" given.)

For the second Exception (Doctrine UniqueConstraintViolationException), I have a nice SQL request returned (which is not good for security and in general in production server)

Have you something to catch it or modify the Doctrine message ?
Or is it something it can be developped in API platform ?
At the moment, any Doctrine Exception will return a SQL message:

  • NotNullConstraintViolationException
  • ForeignKeyConstraintViolationException
  • UniqueConstraintViolationException
  • SyntaxErrorException
  • NonUniqueFieldNameException
  • InvalidFieldNameException
  • TableNotFoundException
  • TableExistsException

Proposed Solution:

In API Platform, the event class responsible to send the data to doctrine (ApiPlatform\Core\Bridge\Doctrine\EventListener\WriteListener), flush the data without catching the Doctrine Exception (line 68)

We need to develop the exception classes above in API Platform and catch the flush operation with theses classes and a better message, am I right ?

Thanks,
Jordan

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    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