doujuegai8830 2018-02-05 09:55
浏览 18

如何在Symfony 4中设置错误处理程序安全网?

PHP offers the possibility to set customer error handlers with set_error_handler("customError",E_USER_WARNING); (for example).

How and where can I set some default error handlers for a Symfony 4 application to make sure I catch all unhandled errors?

I have noticed the Debug component which mentions ErrorHandler::register();. Is this the safety net I am looking for? If yes, where should I put that error handler registration call in my code? Should I modify the index.php page?

  • 写回答

2条回答 默认 最新

  • duanpan3166 2018-02-05 10:09
    关注

    In your index.php, you can use it like below:

    $app->error(function (\Exception $e, $code) use ($app) {
        $errors = [
            [
                'status' => $code,
                'detail' => $e->getMessage()
            ]
        ];
        if ($app['debug'] === true) {
            $errors['file'] = $e->getFile();
            $errors['line'] = $e->getLine();
        }
        return new JsonResponse(['errors' => $errors]);
    });
    
    评论

报告相同问题?

悬赏问题

  • ¥15 msix packaging tool打包问题
  • ¥15 finalshell节点的搭建代码和那个端口代码教程
  • ¥15 用hfss做微带贴片阵列天线的时候分析设置有问题
  • ¥50 我撰写的python爬虫爬不了 要爬的网址有反爬机制
  • ¥15 Centos / PETSc / PETGEM
  • ¥15 centos7.9 IPv6端口telnet和端口监控问题
  • ¥120 计算机网络的新校区组网设计
  • ¥20 完全没有学习过GAN,看了CSDN的一篇文章,里面有代码但是完全不知道如何操作
  • ¥15 使用ue5插件narrative时如何切换关卡也保存叙事任务记录
  • ¥20 海浪数据 南海地区海况数据,波浪数据