Skip to content

Commit 5c0546d

Browse files
Merge pull request #40 from maxhelias/error-handler
Fix fatal error compatibility
2 parents 464448c + 37eefd0 commit 5c0546d

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

EventListener/ReplaceImageListener.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,6 @@
1818

1919
class ReplaceImageListener implements EventSubscriberInterface
2020
{
21-
private const IMAGES_DIR = '../../Resources/public/images';
22-
2321
/** @var string[][] */
2422
private $gifs;
2523

@@ -49,10 +47,16 @@ public function onKernelResponse(ResponseEvent $event)
4947
return;
5048
}
5149

50+
$exception = $event->getRequest()->attributes->get('exception');
5251
// Status code is not set by the exception controller but only by the
5352
// kernel at the very end.
5453
// So lets use the status code from the flatten exception instead.
55-
$statusCode = $event->getRequest()->attributes->get('exception')->getStatusCode();
54+
// Unless it comes from a fatal error handler
55+
if ($exception instanceof \Error) {
56+
$statusCode = $exception->getCode();
57+
} else {
58+
$statusCode = $exception->getStatusCode();
59+
}
5660

5761
$dir = $this->getGifDir($statusCode);
5862
$gif = $this->getRandomGif($dir);

0 commit comments

Comments
 (0)