Reputation: 11
I am making a project in Symfony 5 where there are multiple roles with different privileges. The problem is that when a user tries to log in a zone where they don't have enough privileges (e.g. a USER in an ADMIN only zone) it throws an Access Denied exception and I want to show a custom message instead of the Symfony error screen.
The security part has been done with the access_control method (in case that helps). I've tried following the docs related to this matter but I can't find the way to solve it.
Upvotes: 1
Views: 697
Reputation: 8181
If you want to customize the message and not change the response or the error code itself you can just customize the error template by creating a templates/bundles/TwigBundle/Exception/error403.html.twig
template and clearing your caches.
The page won't be shown in the dev
environment, though, because the default error page is more helpful during development. You can still preview it by accessing /_error/403
.
Upvotes: 2