0
我試圖處理與laravel 5.3自定義錯誤,但似乎無法得到正確捕獲中止(404)。Laravel 5.3錯誤處理從中止()
如果我放棄我的路線(web.php)我得到我的404頁面。
如果我把中止在刀刃上,我得到一個NotFoundHttpException消息,但默認爲我的後備錯誤條件,一個500
應用/異常/ handler.php渲染功能:
// 404 page when a model is not found
if ($exception instanceof ModelNotFoundException or $exception instanceof NotFoundHttpException) {
return response()->view('errors.404', $requestAndException, 404);
}
if ($this->isHttpException($exception)) {
//return $this->renderHttpException($exception);
// mirrored code from renderHttpException to allow for exception-less errors in non-dev mode
$status = $exception->getStatusCode();
if (view()->exists("errors.{$status}")) {
return response()->view("errors.{$status}", $requestAndException, $status, $exception->getHeaders());
} else {
return $this->convertExceptionToResponse($exception);
}
} else {
// Custom error 500 view on production
return response()->view('errors.500', $requestAndException, 500);
}
我試着用特定的例外更新使用部分,但似乎沒有什麼區別。目前坐落於:
use Exception;
use Illuminate\Auth\AuthenticationException;
use Illuminate\Foundation\Exceptions\Handler as ExceptionHandler;
任何想法?
我確實有。這是行不通的。當我在視圖內呼叫放棄時。 「 」如果我放棄我的路線(web.php)我得到我的404頁 如果我放棄刀片,我得到一個NotFoundHttpException消息,但默認爲我的回退錯誤條件,500。 「 –
你不需要把它放在你的路線上,你只需要在錯誤文件夾中用正確的名字創建視圖,laravel會照顧到你的一切。 –
然後放入控制器或中間件。 –