Ibexa DXP Discussions

Community discussion forum for developers working with Ibexa DXP

Make a nice rendering of the AccessDeniedHttpException in production

Salut.

On the dev environment, when I have a user rights problem I have a nice stacktrace symfony with all the details of the error.

In production. I have this very sober message in black on a white background.

Oops! An Error Occurred
The server returned a “403 Forbidden”.
Something is broken. Please let us know what you were doing when this error occurred. We will fix it as soon as possible. Sorry for any inconvenience caused.

How can I stylize this mistake?

Hi @remy_php

You can use standard Symfony way of styling the error messages: https://symfony.com/doc/current/controller/error_pages.html

1 Like

Salut @emodric,

I’ll explore your trail.
In the meantime I had explored this one:

class AccessDeniedHandler implements AccessDeniedHandlerInterface
{
    public function handle(Request $request, AccessDeniedException $accessDeniedException)
    {
        $content = $accessDeniedException->getMessage();
        return new Response($content, 403);
    }
}
security:
    firewalls:
            access_denied_handler: app.security.access_denied_handler
services:
    app.security.access_denied_handler:
        class: MyBundle\AccessDeniedHandler

But without success for the moment. Maybe it’s the wrong firewalls?

Is there a specific reason why you need the custom handler? If it is only to show the custom error page, then the link I’ve posted is all you need.

No reason.

Overriding the Default Error Templates is the solution.

1 Like

Hello Folks,

Sorry to be so late to the thread. I noticed the topic and remembered that BC made an demo bundle to provide for these website requirements a while ago. This bundle might very well be useful to others still.

https://packagist.org/packages/brookinsconsulting/bcerrorpagesbundle

Cheers,
Heath

Salut @bc.heath

I’m looking at this.

My current pb is that the template is also used in the admin. Which doesn’t suit me at all because I made an extends of my front plagelayout…

{% extends "MyBundle::pagelayout.html.twig" %}
{% block content %}
    <h1>Error</h1>
    <p>{{ exception.message }}</p>
{% endblock %}

I try :

{#{% extends viewbaseLayout %}#}
{#{% extends base_template() %}#}
{#{% extends 'pagelayout.html.twig' %}#}
{#{% extends noLayout == true ? viewbaseLayout : pagelayout %}#}
{#{% extends pagelayout %}#}