forked from simplesamlphp/simplesamlphp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExceptionHandler.php
More file actions
53 lines (46 loc) · 1.59 KB
/
ExceptionHandler.php
File metadata and controls
53 lines (46 loc) · 1.59 KB
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
<?php
declare(strict_types=1);
namespace SimpleSAML\Error;
use Error as BuiltinError;
use Exception as BuiltinException;
use SimpleSAML\Event\ExceptionHandlerEvent;
use SimpleSAML\Event\Dispatcher\ModuleEventDispatcherFactory;
use SimpleSAML\Logger;
use SimpleSAML\Module;
use Symfony\Component\HttpKernel\Exception\MethodNotAllowedHttpException;
use Throwable;
use function class_exists;
/**
* SimpleSAMLphp's custom exception handler.
*
* @package SimpleSAMLphp
*/
class ExceptionHandler
{
/**
* @param \Throwable $exception
* @return void
* @throws \SimpleSAML\Error\Exception
* @throws \Throwable
*/
public function customExceptionHandler(Throwable $exception): void
{
$eventDispatcher = ModuleEventDispatcherFactory::getInstance();
/** @var ExceptionHandlerEvent $event */
$event = $eventDispatcher->dispatch(new ExceptionHandlerEvent($exception));
$exception = $event->getException();
Module::callHooks('exception_handler', $exception);
if ($exception instanceof MethodNotAllowedHttpException) {
$e = new MethodNotAllowed($exception);
$e->show(Logger::DEBUG, true);
} elseif ($exception instanceof Error) {
$exception->show();
} elseif ($exception instanceof BuiltinException) {
$e = new Error(ErrorCodes::UNHANDLEDEXCEPTION, $exception);
$e->show();
} elseif (class_exists('Error') && $exception instanceof BuiltinError) {
$e = new Error(ErrorCodes::UNHANDLEDEXCEPTION, $exception);
$e->show();
}
}
}