Quantcast
Channel: Active questions tagged symfony4 - Stack Overflow
Viewing all articles
Browse latest Browse all 3924

Symfony 4.4 - Custom error pages not working when exception controller is enabled

$
0
0

When implementing fos_rest bundle with symfony, I cannot seem to have symfony's normal behavior when handling custom error pages on a 404, 405, 500 or any other error triggered by symfony.

It works fine for every error triggered with the rest bundle in a normal rest controller.

But on my landing page (and about us and so on), which is not using fos_rest bundle, but twig instead, the custom error pages don't work, instead, it seems to be handled by the fos_rest bundle anyway, and always sends a default error 500 (even if it should be triggering a 404 error).

If I deactivate exceptions in fos_rest.yaml file (enabled: false), then, the custom error pages works fine (configured following this documentation here: https://symfony.com/doc/4.4/controller/error_pages.html )

fos_rest:
    routing_loader:
        default_format: json
        include_format: false
    body_listener: true
    format_listener:
        rules:
            - { path: '^/myROUTE1', priorities: ['json'], fallback_format: json, prefer_extension: false }
            - { path: '^/myROUTE2', priorities: ['json'], fallback_format: json, prefer_extension: false }
            - { path: '^/myROUTE3', priorities: ['json'], fallback_format: json, prefer_extension: false }
            - { path: '^/myROUTE4', priorities: ['json'], fallback_format: json, prefer_extension: false }
            - { path: '^/', priorities: ['html', 'json'], fallback_format: 'html' }
    param_fetcher_listener: true
    access_denied_listener:
        json: true
    view:
        view_response_listener: 'force'
        formats:
            json: true
    exception:
        enabled: true
        exception_controller: 'fos_rest.exception.controller:showAction'
        codes:
            Doctrine\ORM\EntityNotFoundException: 404
            \LogicException: 400
            \DomainException: 400
        messages:
            Doctrine\ORM\EntityNotFoundException: true
            \LogicException: true
            \DomainException: true

How do I set up fos_rest bundle to only handle exceptions for the routes handled by my rest controllers, and leave the normal symfony 4 behavior for the rest of the site?

Thank you for your help.


Viewing all articles
Browse latest Browse all 3924

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>