Laravel 4 Exception: NotFoundHttpException

后端 未结 6 854
时光说笑
时光说笑 2020-12-30 07:14

My Laravel 4 application\'s logs sometimes show a NotFoundHttpException:

exception \'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpExce         


        
6条回答
  •  感动是毒
    2020-12-30 07:32

    A NotFoundHttpException is basically just a 404 in your application. Unfortunately the exception message doesn't even tell you the URL of the request that triggered the exception, which makes it difficult to understand these errors when you see them in your logs.

    To give you more debugging information, set up your own 404 handler. Here's a simple handler which will log the URL (so you know what was requested to trigger the error) and the user agent (to help you figure out who or what made the request) and return a view and 404 code:

    App::missing(function($e) {
        $url = Request::fullUrl();
        $userAgent = Request::header('user-agent');
        Log::warning("404 for URL: $url requested by user agent: $userAgent");
        return Response::view('errors.not-found', array(), 404);
    });
    

    Put it in app/start/global.php.

提交回复
热议问题