My Laravel 4 application\'s logs sometimes show a NotFoundHttpException
:
exception \'Symfony\\Component\\HttpKernel\\Exception\\NotFoundHttpExce
I got this error because i used method="post" in my form instead of method="POST".
Might be useful to someone.
My project is in C:\xampp\htdocs\ColorTex
I got this error by typing
http://localhost/myproject/public/image
instead of
http://localhost/MyProject/public/image
I'm in windows, so I thought it will ignore capitalization, but...
Be careful with that.
I got this problem because I had capitalized the name of a parent directory and didn't capitalize it in the URL. That's why I got the error.
I was using this url localhost/laravel/todo2/public/foo and in fact it worked if all I typed was: localhost/Laravel/todo2/public/ but if I typed anything after the public/ it would give that error.
if I used this with Laravel capitalized localhost/Laravel/todo2/public/foo
the routes after public/ would work
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
.
It's really hard to say for sure what is causing this without knowing your code. Looking at the stack trace of the error, it's clear that the Router is dispatching it and I guess it has nothing to do with the background job itself, but rather the API's it calls.
In your specific case, the exception is throw after a ResourceNotFoundException, which happens when there's no route defined for such URL pattern.
Possible problems:
If the background job does a file_get_contents
or curl
on your own API's, it may be calling a route that does not exist and then throwing that exception.
If you don't have control of the URL's the background job is downloading, it may be trying to fetch an URL like 127.0.0.1
, localhost
or anything like that.
You can filter 404 (NotFoundHttpException) error form your log file.
File location : app/start/global.php
App::error(function(Exception $exception, $errorCode)
{
$requestUrl = Request::fullUrl();
$userAgent = Request::header('user-agent');
if($errorCode != 404){
Log::error('Exception', array(
'errorCode' => $errorCode,
'requestUrl' => $requestUrl,
'userAgent' => $userAgent,
'context' => $exception,
));
}
return Response::view('error-page-path.error-404', array(), 404);
// Here "error-404" is a blade view file in "error-page-path" directory
});