【问题标题】:Laravel not displaying debug messages after adding custom error pages添加自定义错误页面后,Laravel 不显示调试消息
【发布时间】:2015-02-22 09:15:15
【问题描述】:

我希望我的 Laravel (4.2) 网站在发生错误时返回一些自定义错误消息(而不是 Whoops, looks like something went wrong.),所以我添加了以下内容:

App::error(function(Exception $exception, $code)
{
    Log::error($exception);

    return Response::view('errors.500', [], 500);
});

use Illuminate\Database\Eloquent\ModelNotFoundException;
App::error(function(ModelNotFoundException $e)
{
    return Response::view('errors.404', [], 404);
});

app/start/global.php

测试我临时更改的页面:'debug' => false in app/config/local/app.php

我的自定义错误页面显示正确(发生错误时)。但是,即使我将本地开发配置恢复为 'debug' => true,它们仍在显示(而不是带有堆栈跟踪和错误消息的错误页面)。

我尝试将以下内容粘贴到app/start/local.php,希望当 laravel 在本地环境中时它会覆盖全局错误处理。但这并不能解决问题。

App::error(function(Exception $exception, $code)
{
    Log::error($exception);
});

use Illuminate\Database\Eloquent\ModelNotFoundException;
App::error(function(ModelNotFoundException $e)
{
    Log::error($exception);    
});

如何让 laravel 再次显示错误堆栈跟踪?

【问题讨论】:

    标签: php laravel web error-handling


    【解决方案1】:

    问题在于,如果你从 App::error 处理程序返回某些内容,Laravel 就会将其用作响应并停止“冒泡”。

    最简单的方法就是检查app.debug 配置:

    App::error(function(Exception $exception, $code)
    {
        Log::error($exception);
        if(Config::get('app.debug') !== true){
            return Response::view('errors.500', [], 500);
        }
    });
    
    use Illuminate\Database\Eloquent\ModelNotFoundException;
    App::error(function(ModelNotFoundException $e)
    {
        if(Config::get('app.debug') !== true){
            return Response::view('errors.404', [], 404);
        }
    });
    

    【讨论】:

      猜你喜欢
      • 2013-06-16
      • 2016-04-17
      • 1970-01-01
      • 2017-05-30
      • 2017-08-10
      • 2016-09-19
      • 1970-01-01
      • 2016-08-06
      • 2013-07-18
      相关资源
      最近更新 更多