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); }