0

我正在使用 Laravel 5.5,我意识到在这个版本中,错误似乎有点“用户友好”......如何再次获取详细的错误消息?

例如:之前,使用此代码:

abort(500, 'The server is on fire');

我看到这条消息“服务器着火了”。现在,我看到的只是“哎呀,好像出了点问题。”

提前致谢!

4

1 回答 1

0

您收到此错误的原因是您正在使用 500 代码中止。Laravel 最终会检查是否存在与该错误代码相关的错误视图(存在),然后显示该视图。

开箱即用的 Laravel 带有 404、419、429、500、503 错误视图。

我建议使用更适合您情况的代码(如果可能)。这是一些错误代码的列表https://httpstatuses.com/

如果您无法通过将以下内容添加到您的app/Exceptions/Handler.php类来覆盖默认行为:

/**
 * Render the given HttpException.
 *
 * @param  \Symfony\Component\HttpKernel\Exception\HttpException  $e
 * @return \Symfony\Component\HttpFoundation\Response
 */
protected function renderHttpException(HttpException $e)
{
    $status = $e->getStatusCode();

    if ($status == 500 && config('app.debug')) {
        return $this->convertExceptionToResponse($e);
    }

    return parent::renderHttpException($e);

从本质上讲,这将绕过寻找500.blade.php错误视图,然后应该用哎呀显示堆栈。请注意,这没有针对实际的 500 错误进行测试,所以我不确定它是否适用(我想不出为什么它不会,但我只是想提一下)。

于 2017-09-12T09:26:19.953 回答