gpt4 book ai didi

php - Symfony2-特定捆绑软件的错误处理程序

转载 作者:行者123 更新时间:2023-12-03 08:53:17 25 4
gpt4 key购买 nike

在我当前的项目中,我有几个 bundle 包。一个 bundle 包用于REST API,在其中我需要使用自定义消息返回有关错误的JsonResponse。其他 bundle 软件应显示HTML错误页面。现在,我添加了带有“onKernelException” -Method的“ExceptionListener”,不幸的是,它将始终被触发。

如何为每个 bundle 包设置不同的错误处理?还是有一些好的/可行的/其他的方式来设置不同的响应,如果根据 bundle 发生了错误?

最佳答案

用您自己的类(RestfulJsonResponse extends JsonResponse)扩展JsonResponse,并使所有响应都使用 bundle 包中的新响应(use RestfulJsonResponse as JsonResponse)

然后在您的监听器中,只需检查响应的类型:

if ($response instanceof RestfulJsonResponse) {
// do your thing
}

关于php - Symfony2-特定捆绑软件的错误处理程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35630015/

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