Skip to content

Commit

Permalink
Merge pull request #40 from maxhelias/error-handler
Browse files Browse the repository at this point in the history
Fix fatal error compatibility
  • Loading branch information
damienalexandre authored Aug 5, 2020
2 parents 464448c + 37eefd0 commit 5c0546d
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions EventListener/ReplaceImageListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@

class ReplaceImageListener implements EventSubscriberInterface
{
private const IMAGES_DIR = '../../Resources/public/images';

/** @var string[][] */
private $gifs;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 5c0546d

Please sign in to comment.