forked from Rudloff/alltube
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ErrorHandler.php
36 lines (30 loc) · 946 Bytes
/
ErrorHandler.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
<?php
namespace Alltube;
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
*/
public static function handle(Throwable $e)
{
error_log($e);
if (class_exists(HtmlErrorRenderer::class)) {
// If dev dependencies are loaded, we can use symfony/error-handler.
$renderer = new HtmlErrorRenderer(true, null, null, dirname(__DIR__));
$exception = $renderer->render($e);
http_response_code($exception->getStatusCode());
die($exception->getAsString());
} else {
http_response_code(500);
die('Error when starting the app: ' . htmlentities($e->getMessage()));
}
}
}