From 37eefd07f7abb1d007630c4503d72e7154c3332a Mon Sep 17 00:00:00 2001 From: maxhelias Date: Wed, 5 Aug 2020 00:29:49 +0200 Subject: [PATCH] Fix fatal error compatibility --- EventListener/ReplaceImageListener.php | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/EventListener/ReplaceImageListener.php b/EventListener/ReplaceImageListener.php index 360735a..1f5371e 100644 --- a/EventListener/ReplaceImageListener.php +++ b/EventListener/ReplaceImageListener.php @@ -18,8 +18,6 @@ class ReplaceImageListener implements EventSubscriberInterface { - private const IMAGES_DIR = '../../Resources/public/images'; - /** @var string[][] */ private $gifs; @@ -49,10 +47,16 @@ public function onKernelResponse(ResponseEvent $event) return; } + $exception = $event->getRequest()->attributes->get('exception'); // Status code is not set by the exception controller but only by the // kernel at the very end. // So lets use the status code from the flatten exception instead. - $statusCode = $event->getRequest()->attributes->get('exception')->getStatusCode(); + // Unless it comes from a fatal error handler + if ($exception instanceof \Error) { + $statusCode = $exception->getCode(); + } else { + $statusCode = $exception->getStatusCode(); + } $dir = $this->getGifDir($statusCode); $gif = $this->getRandomGif($dir);