gpt4 book ai didi

symfony - FOSRestBundle:未触发 ExceptionController

转载 作者:行者123 更新时间:2023-12-03 02:54:48 25 4
gpt4 key购买 nike

config.yml:

twig:
debug: %kernel.debug%
strict_variables: %kernel.debug%
exception_controller: 'FOS\RestBundle\Controller\ExceptionController::showAction'

fos_rest:
routing_loader:
default_format: json
view:
view_response_listener: force
force_redirects:
html: true
format_listener:
rules:
- { path: '^/api', fallback_format: json }
- { path: '^/', fallback_format: html }
param_fetcher_listener: force
body_listener: true
exception:
codes:
'Symfony\Component\Routing\Exception\ResourceNotFoundException': 404
'Symfony\Component\HttpKernel\Exception\NotFoundHttpException': 404
'Doctrine\ORM\OptimisticLockException': HTTP_CONFLICT

但是返回的是html:

...<h2><span>2/2</span> <abbr title="Symfony\Component\HttpKernel\Exception\NotFoundHttpException">NotFoundHttpException</abbr>: No route found for "GET /api/user/jFvms0rp%20"</h2>...

如何将其转为json?

最佳答案

我解决了同样的问题:

这是我的配置:

fos_rest:
body_listener: true
view:
view_response_listener: force
format_listener:
rules:
- { path: '^/', fallback_format: json }

希望对你有帮助

关于symfony - FOSRestBundle:未触发 ExceptionController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20904867/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com