@@ -37,6 +37,10 @@ public function onKernelResponse(ResponseEvent $event): void
3737 }
3838
3939 $ exception = $ event ->getRequest ()->attributes ->get ('exception ' );
40+ if (!($ exception instanceof \Throwable)) {
41+ return ;
42+ }
43+
4044 // Status code is not set by the exception controller but only by the
4145 // kernel at the very end.
4246 // So lets use the status code from the flatten exception instead.
@@ -51,7 +55,7 @@ public function onKernelResponse(ResponseEvent $event): void
5155 $ gif = $ this ->getRandomGif ($ dir );
5256 $ url = $ this ->getGifUrl ($ dir , $ gif );
5357
54- $ content = $ event ->getResponse ()->getContent ();
58+ $ content = ( string ) $ event ->getResponse ()->getContent ();
5559
5660 $ content = preg_replace (
5761 '@<div class="exception-illustration hidden-xs-down">(.*?)</div>@ims ' ,
@@ -62,9 +66,6 @@ public function onKernelResponse(ResponseEvent $event): void
6266 $ event ->getResponse ()->setContent ($ content );
6367 }
6468
65- /**
66- * {@inheritdoc}
67- */
6869 public static function getSubscribedEvents (): array
6970 {
7071 return [
@@ -78,7 +79,7 @@ public static function getSubscribedEvents(): array
7879 private function getGifDir (int $ statusCode ): string
7980 {
8081 if (\array_key_exists ($ statusCode , $ this ->gifs ) && \count ($ this ->gifs [$ statusCode ]) > 0 ) {
81- return $ statusCode ;
82+ return ( string ) $ statusCode ;
8283 }
8384
8485 return 'other ' ;
@@ -89,6 +90,10 @@ private function getGifDir(int $statusCode): string
8990 */
9091 private function getRandomGif (string $ dir ): string
9192 {
93+ if (!\array_key_exists ($ dir , $ this ->gifs ) || 0 === \count ($ this ->gifs [$ dir ])) {
94+ return '' ;
95+ }
96+
9297 $ imageIndex = random_int (0 , \count ($ this ->gifs [$ dir ]) - 1 );
9398
9499 return $ this ->gifs [$ dir ][$ imageIndex ];
0 commit comments