code: public function onKernelException(GetResponseForExceptionEvent $event): void
      {
          if (!$event->isMasterRequest()) {
              return;
          }
  
          $request = $event->getRequest();
  
          if ('html' !== $request->getRequestFormat()) {
              return;
          }
  
          if (!AcceptHeader::fromString($request->headers->get('Accept'))->has('text/html')) {
              return;
          }
  
          $this->handleException($event);
      }
docs: Map an exception to an error screen.