Symfony2 FOS Rest错误页面仅在调试中

时间:2015-08-03 09:14:02

标签: symfony fosrestbundle

我遇到的问题是我在fos_rest中配置的所有错误页面只能在调试模式下工作。

FOS\RestBundle\Controller\ExceptionController 

只有在启用调试时,异常控制器才会正确地从http://symfony.com/doc/current/cookbook/controller/error_pages.html找到我的自定义Twig错误页面。 然而,当我禁用调试模式时,我在https://github.com/FriendsOfSymfony/FOSRestBundle/blob/master/Controller/ExceptionController.php#L104中抛出一个异常 Twig正在抱怨它的404,尽管它已经弄清了它的映射。

我的配置:

fos_rest:
    disable_csrf_role: ROLE_USER
    routing_loader:
        default_format: json
        include_format: false
    service:
        exception_handler:    fos_rest.view.exception_wrapper_handler
    exception:
        enabled: true
        codes:
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Symfony\Component\HttpKernel\Exception\NotFoundHttpException': 404
            'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
            'Symfony\Component\Security\Core\Exception\AccessDeniedException': 403
            'Symfony\Component\Security\Core\Exception\DisabledException': 403
            'Doctrine\DBAL\Exception\ServerException': 500
        codes:
        messages:
            'Symfony\Component\Translation\Exception\NotFoundResourceException': false
            'Symfony\Component\Security\Core\Exception\AccessDeniedException': true
            'Symfony\Component\Security\Core\Exception\DisabledException': true
            'Doctrine\DBAL\Exception\ServerException': false
    body_listener: true
    view:
        view_response_listener: true
        formats:
            json: true
            xml: false
            html: true
        templating_formats:
            json: false
            xml: false
            html: true
        force_redirects:
            html: true
        failed_validation: HTTP_BAD_REQUEST
        default_engine: twig
    format_listener:
        rules:
            - priorities: [json, html]
            - fallback_format: json
            - { path: '^/css', priorities: [ 'text/css', '*/*'], fallback_format: css, prefer_extension: true }                        
            - { path: '^/api', priorities: [ 'json', 'text/html'], fallback_format: json, prefer_extension: false }
            - { path: '^/', priorities: [ 'text/html', '*/*'], fallback_format: json, prefer_extension: false }

0 个答案:

没有答案