2020-10-18 10:03:57 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Alltube;
|
|
|
|
|
2022-01-26 22:58:25 +00:00
|
|
|
use Slim\Http\StatusCode;
|
2020-10-18 10:03:57 +00:00
|
|
|
use Symfony\Component\ErrorHandler\ErrorRenderer\HtmlErrorRenderer;
|
|
|
|
use Throwable;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Class ErrorHandler
|
|
|
|
* @package Alltube
|
|
|
|
*/
|
|
|
|
class ErrorHandler
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Last resort if the error has not been caught by the Slim error handler for some reason.
|
|
|
|
* @param Throwable $e
|
|
|
|
* @return void
|
|
|
|
*/
|
2022-05-28 21:43:07 +00:00
|
|
|
public static function handle(Throwable $e): void
|
2020-10-18 10:03:57 +00:00
|
|
|
{
|
|
|
|
error_log($e);
|
|
|
|
|
|
|
|
if (class_exists(HtmlErrorRenderer::class)) {
|
|
|
|
// If dev dependencies are loaded, we can use symfony/error-handler.
|
2021-02-09 21:17:29 +00:00
|
|
|
$renderer = new HtmlErrorRenderer(true, null, null, dirname(__DIR__));
|
2020-10-18 10:03:57 +00:00
|
|
|
$exception = $renderer->render($e);
|
|
|
|
|
|
|
|
http_response_code($exception->getStatusCode());
|
|
|
|
die($exception->getAsString());
|
|
|
|
} else {
|
2022-01-26 22:58:25 +00:00
|
|
|
http_response_code(StatusCode::HTTP_INTERNAL_SERVER_ERROR);
|
2020-10-18 10:03:57 +00:00
|
|
|
die('Error when starting the app: ' . htmlentities($e->getMessage()));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|