Skip to content

Error pages in EasyAdmin #7185

@Daniel-Garmig

Description

@Daniel-Garmig

Hi!

I have some custom controllers using #[AdminRoute()] to integrate them into EasyAdmin. When I need to throw errors (for example, a entity don't exist) I want to show a error page to the user instead of just throwing the exception.

I can create my own error page extending EasyAdmin layouts and redirect to that route. But I wonder if EasyAdmin already provide something built-in for this.

I found the following in the source:

When there is an uncontrolled exception in EasyAdmin and it's a "EasyAdmin exception", the exception twig template is rendered (see https://github.com/EasyCorp/EasyAdminBundle/blob/6549e838ae68fdc2ef5a59f340d3629dc7221177/src/EventListener/ExceptionListener.php).

I didn't find anything in the docs about how to show custom errors using EasyAdmin exception/error page. Is there a way to do it?
I tried throwing one of EasyAdmin exceptions, but it's constructor params doesn't seems quite user-friendly.

if ($entity == null) {
    throw new EntityNotFoundException(["entity_name" => "roomCategory", "entity_id_name" => "id", "entity_id_value" => $idValue]);
}

If it's not currently possible to do, maybe it can be added as a new feature.
For example:

  • New exception class AdminException with easier and documented parameters for it's constructor.
  • Maybe a builder class (AdminExceptionBuilder/AdminErrorBuilder) to help create and configure this errors and to the AdminException instance.
    Then, the exception can be thrown and it should be handled by EasyAdmin ExceptionListener.

Thank you :)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions