Registering a 404 Error Handler

Problem

You want to trap any 404 errors you application generates.

Solution

Use the App::missing() method.

You'll place this code somewhere in your startup code. Usually app/start/global.php.

App::missing(function($exception)
{
    return View::make('not-found')->withMessage($exception->getMessage());
});

Discussion

Return a Response with your handler to finish the processing.

In other words, if your missing handler returns anything, all further error handlers will be ignored and the response will be returned to the user.

Sometimes, such as error logging, you don't want your handler to return anything. You may want it to do a bit of processing and allow other handlers to continue as normal.

comments powered by Disqus