Handling Session Database Errors
Hello,
I am working on implementing database sessions. I want to make sure that my application fails gracefully if for instance the database is unavailable.
A simple way is to catch any Exceptions at the application level and display a custom error view. However, in doing this I notice that the laravel default error page displays instead of my custom page. In looking further and the laravel code I noticed that the location where the default page is coming from is vendor\symfony\debug\Symfony\Component\Debug\ExceptionHandler.php:~240.
I assume that since creating sessions is one of the first things that happens in the application life cycle using the following code doesn't work.
App::fatal(function($exception)
{
// Log error
return Response::view('custom-down-page', [], 500);
});
The only other thought I had to fix this issue is to add a try catch block to the entire public\index.php file. Something like this.
try
{
//...
$app->run();
}
catch(Exception $e)
{
// Log error
echo file_get_contents(__DIR__.'/custom-down-page.html');
}
Is there a better way to handle this?
Thanks in advance.
Please or to participate in this conversation.