【问题标题】:Whoops, looks like something went wrong. Even when app_debug=true哎呀,看起来像出事了。即使 app_debug=true
【发布时间】:2018-09-21 22:22:45
【问题描述】:

在全新的 Laravel 5.6 安装(APP_DEBUG=true 在.env 文件中)一切正常,除了这种情况:

当使用abort(500, 'test exception'); 时,它会显示“糟糕,好像出了点问题。” 页面。

当使用abort(501, 'test exception');时,会显示异常追踪页面。

我的问题是:当异常代码在 .env 文件中为 500 和 APP_DEBUG=true 时,为什么我得到 “糟糕,好像出了点问题。”?

当错误码为 500 时如何在不删除vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/views/500.blade.php 的情况下显示正常的异常信息/跟踪。

【问题讨论】:

  • 你说的都是httpexceptions是对的。 Here's an actual solution 具有覆盖 Exception\handler.php 中的 renderHttpException 的函数。 (我删除了我的答案。)
  • 要使链接的答案起作用,您必须在 handler.php 的顶部添加 use Symfony\Component\HttpKernel\Exception\HttpException;。
  • 感谢ourmandave,将此作为答案发布,以便我为您接受。

标签: php laravel


【解决方案1】:

正如我们的建议,解决方案是覆盖 App\Exceptions\Handler.php 中的 renderHttpException 函数,如下所示:

protected function renderHttpException(HttpException $e)
{
    if (config('app.debug') === true) {
        //this shows Laravel exception page
        return $this->convertExceptionToResponse($e);
    }
    //continue as normal
    return parent::renderHttpException($e);
}

【讨论】:

    猜你喜欢
    • 2016-12-12
    • 2017-10-12
    • 2015-10-29
    • 2015-05-07
    • 2018-04-18
    • 2014-07-13
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    相关资源
    最近更新 更多