[Bug] 404 Exceptions no longer logging broken url correctly
Hi,
The old 4.0 exceptions would include information about a 404 exception, so you could fix the problem.
4.1 no longer includes this in the log file - it is blank where the data should be.
See this for an example: http://paste.laravel.com/1g2Y
No reason you should rely on this instead of adding your own App::missing handler that logs the info you need, IMO.
Maybe - except it is an undocumented change in behavior from 4.0 - so it either needs to be explicit that this is a permanent change, or its a bug.
Personally I think if we are logged a 404 by default, then that information is not very useful without knowing which route triggered the 404 so you can track it down.
There may be a bigger issue here. It seems that there is no route information available from the missingException (or whatever it is called), possibly other exceptions, too.
Try running:
App::missing(function($exception)
{
dd(Route::current());
// or dd(Route::currentRouteName());
// or dd(Route::is('anything'));
});
Whoops, FatalErrorException.
If this is the desired behavior, I wonder how one would reuse a layout view that checks the current route for active states and such, when an error occurs. This stuff works in 4.0.
Considering a 404 usually occurs when no route is found for the URL, it makes perfect sense that trying to get the current route's name won't work.
Are you sure? Let's say you go to example.com/nopagehere. It would be nice to know that it was "nopagehere" that didn't work out for them. Might as well through in a fatal error due to the Route:: calls on the template, for good measure. Double the errors, double the fun.
My point is that if a user makes it to your app, there is always a route. It may not be 100% valid, but it's a route indeed.
P.S. I'm okay with the route name as an empty string. Just need the object to avoid errors.
I don't think there is always a route. In this case if they are 404ing they are likely not hitting any route. So I disagree that Route::current() should return anything. I think what you need is method similar to what @anlutro says below in order to get the requested URI. It shouldn't return a route if you do not hit one.
Request::fullUrl() ?
It seems like using Request::is() for templates is the answer. However, your site will break if you change a path. For example, if I check to see if 'contact' is the current path, in a template using
Request::is('contact')
Then, I change the route
// Old route
// Route::get('contact', ['as' => 'contact', 'uses' => 'SiteController@contact']);
// New route
Route::get('contact_us', ['as' => 'contact', 'uses' => 'SiteController@contact']);
This breaks if there is an exception or not. Remember, named routes are the things that stopped this breakage. Since we can't use the static Route:: in a templates, due to it causing a fatal exception on an invalid route, we have to use Request::, not route names. So, are we back to the old search and replace, or, is it better to provide the route object, even when the route doesn't match?
To clarify, I'm not trying to get the failed path from Route::. I just want calls to Route::is('home'), for example, to be False when displaying that template when a NotFoundException occurs. So, it's not the home or another navigation linked page, great, don't set the active state in the template. It shouldn't be a fatal error.
So, am I right, wrong or crazy? Pick two.
I just tested 404s in 4.0 and can't duplicate that JSON version you are seeing. I would just use App::missing and then log Request::fullUrl().