php - 启用异常控制器时自定义错误页面不起作用
问题描述
当使用 symfony 实现 fos_rest 包时,在处理 404、405、500 或由 Symfony 触发的任何其他错误上的自定义错误页面时,我似乎无法获得 Symfony 的正常行为。
它适用于普通休息控制器中休息包触发的每个错误。
但是在我的登陆页面(以及关于我们等)上,它没有使用 fos_rest 包,而是使用 twig,自定义错误页面不起作用,相反,它似乎由 fos_rest 包处理,并且总是发送默认错误 500(即使它应该触发 404 错误)。
如果我在 fos_rest.yaml文件enabled: false
(
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
如何设置 fos_rest 包以仅处理由我的休息控制器处理的路由的异常,并为站点的其余部分保留正常的 Symfony 4 行为?
解决方案
我通过使用区域找到了解决方案。我必须在我的 fos_rest.yaml 中添加以下代码
zone:
- { path: '^/myROUTE1' }
- { path: '^/myROUTE2' }
- { path: '^/myROUTE3' }
- { path: '^/myROUTE4' }
如此处所述
希望这可以帮助。
推荐阅读
- javascript - 如何在没有按钮的情况下控制 React-Bootstrap Dropdown 的可见性?
- c++ - 将通用引用转换为可调用的 void 指针,反之亦然
- sql - 使用局部变量时选项重新编译更快
- google-data-studio - Google Data Studio:不要在时间序列图表中显示空值
- spring - 我可以将@ConditionalProperty 与我的自定义注释一起使用以避免重复配置吗?
- javascript - 等待反应和反应角色
- google-kubernetes-engine - 如何在 GKE 上将 opa 部署为 side car 后找到 OPA url
- javascript - 在 React Native 中使用返回无法访问的代码
- ruby-on-rails - 为包含的方法调用 super 会导致“无超类方法”错误 - ActiveSupport
- python - WebScraping w/ Beautiful Soup:如何返回列表中的空元素?