【问题标题】:Laravel show Whoops debugger in dev environmentLaravel 在开发环境中展示 Whoops 调试器
【发布时间】:2014-10-05 20:37:34
【问题描述】:

我需要在我的业务逻辑中包含 try-catch 块。因此,我可以使用更多上下文记录错误。

try {
    // business logic
} catch(Exception $e) {
    // Log message like 'Could not create user with email something@domain.com'
    $msgForUser = CustomErrorHandler::handleError($e, $data->email);

    // Display message like 'Your user was not created bla bla bla'
    return $msgForUser;
}

我意识到我可以在 start/global.php 中的 App::error 中设置自定义错误处理,但是这消除了包含特定于该函数的变量和消息的机会。

问题是现在我的 try 块捕获了开发中的错误。而且我还想在开发模式下获得 Whoops 异常调试器。这可能吗?

【问题讨论】:

    标签: php laravel exception-handling whoops


    【解决方案1】:

    你有点反对这个流程,Laravel 似乎偏向于使用异常来报告实际错误(而不是像你一样使用异常来进行应用程序控制流)。

    在 Laravel 中(我知道)没有任何东西可以让你这样做。我会把这个逻辑放在你的 CustomErrorHandler::handleError 方法中

    class CustomerErrorHandler
    {
        //assuming `CustomerErrorHandler::handleError` is a static method
        //call.  If its a facade define an instance method in your service
        //class.
        static public function handleError($e)
        {
            if(...is environment where I want to see whoops...)
            {
                throw $e;
            }
    
            //if we're still here it's production
            //so do our logging and create a 
            //$msgForUser string
    
            //...
    
            return $msgForUser;
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2014-06-11
      • 1970-01-01
      • 2014-11-03
      • 1970-01-01
      • 2020-09-29
      • 1970-01-01
      • 2015-04-04
      • 2021-06-12
      • 1970-01-01
      相关资源
      最近更新 更多