簡體   English   中英

錯誤處理程序未捕獲 Laravel 中的錯誤 500

[英]error handler not catching error 500 in Laravel

以下是handler.php文件中的function:

public function render($request, Exception $exception)
{
    if ($exception instanceof CustomException) {
        return response()->view('errors.500', [], 500);
    }

    return parent::render($request, $exception);
}

我在以下路徑中有一個名為 500.blade.php 的刀片:

C:\xampp\htdocs\sharp\resources\views\errors

以下是我正在嘗試處理的錯誤 500(沒有任何處理):

localhost is currently unable to handle this request.
HTTP ERROR 500

如果我添加上面提到的public function render($request, Exception $exception) function,if條件將不起作用,並且會顯示默認錯誤,即:

Whoops, looks like something went wrong.

我不確定為什么 if 條件沒有收到錯誤。

錯誤 500:

在此處輸入圖像描述

如果您希望所有status code = 500到 go 通過特定頁面,您可以執行以下操作:

if ($this->isHttpException($exception)) {

        if ($exception->getStatusCode() == 500) {
            return response()->view('errors.500' , [], 500);
        }

    }
if ($exception instanceof ErrorException) {
        abort(500);
    }
return parent::render($request, $exception);

但如果錯誤僅為instanceof CustomException ,您的方法效果很好。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM