From 07f19a80f425ad77e03b9cc2a2e2b1a35ada1da3 Mon Sep 17 00:00:00 2001 From: Pierre Rudloff Date: Sun, 18 Oct 2020 12:03:57 +0200 Subject: [PATCH] Improve fallback error handling --- classes/ErrorHandler.php | 36 ++++++++++++++++++++++++++++++++++++ index.php | 4 ++-- 2 files changed, 38 insertions(+), 2 deletions(-) create mode 100644 classes/ErrorHandler.php diff --git a/classes/ErrorHandler.php b/classes/ErrorHandler.php new file mode 100644 index 0000000..4111da9 --- /dev/null +++ b/classes/ErrorHandler.php @@ -0,0 +1,36 @@ +render($e); + + http_response_code($exception->getStatusCode()); + die($exception->getAsString()); + } else { + http_response_code(500); + die('Error when starting the app: ' . htmlentities($e->getMessage())); + } + } +} diff --git a/index.php b/index.php index ed774bd..7368054 100644 --- a/index.php +++ b/index.php @@ -6,6 +6,7 @@ use Alltube\ConfigFactory; use Alltube\Controller\DownloadController; use Alltube\Controller\FrontController; use Alltube\Controller\JsonController; +use Alltube\ErrorHandler; use Alltube\LocaleManagerFactory; use Alltube\LocaleMiddleware; use Alltube\LoggerFactory; @@ -87,6 +88,5 @@ try { $app->run(); } catch (Throwable $e) { - // Last resort if the error has not been caught by the error handler for some reason. - die('Error when starting the app: ' . htmlentities($e->getMessage())); + ErrorHandler::handle($e); }