Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customise error message for ModelManagerException #8137

Closed
wadjei opened this issue Dec 8, 2023 · 1 comment · Fixed by #8141
Closed

Customise error message for ModelManagerException #8137

wadjei opened this issue Dec 8, 2023 · 1 comment · Fixed by #8141
Labels

Comments

@wadjei
Copy link
Contributor

wadjei commented Dec 8, 2023

Feature Request

Following from #7759, it is not possible to use the feature when the exception is of type ModelManagerException, even though these implement ModelManagerThrowable, as is the case for Doctrine UniqueConstraintViolationExceptions.

This is because, in CRUDController.php ModelManagerExceptions are caught first, before the catch for ModelManagerThrowable.

The relevant catches have been marked for removal for the last couple of years // NEXT_MAJOR: Remove this catch. but persist in the current 4.x and 5.x branches.

Currently, I'm having to hack around this issue by overriding addFlash, disabling the call to the CRUDController method for cases where I want to customise the message and storing the custom message in the admin (if there is one) so that I can retrieve it in the controller, before re-enabling the call to the CRUDController afterwards.

I see three possible clean resolutions to this:

  1. remove the catch blocks that have been earmarked since 2021 (this may have B.C. issues for some projects);
  2. swap the ordering of the ModelManagerThrowable and ModelManagerException catch blocks so that ModelManagerThrowable is handled first;
  3. apply a similar interface to handleModelManagerException so that it can also return a customised string.

I prefer option 3... is there any reason why this was not done at the same time as #7761 ?

@wadjei
Copy link
Contributor Author

wadjei commented Dec 13, 2023

Hey @VincentLanglet I was having trouble getting handleModelManagerThrowable to customise the flashbag message on error and came up with the proposed PR #8141

WDYT?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant