Infinite loop with custom DefaultExceptionHtmlSubscriber and JSON:API\REST endpoint

Created on 12 March 2024, 10 months ago
Updated 19 March 2024, 9 months ago

Problem/Motivation

The site ends up in a infinite loops while using a custom class extending DefaultExceptionHtmlSubscriber and JSON:API or REST resource.

Steps to reproduce

Implement a basic subscriber extending DefaultExceptionHtmlSubscriber

final class MyEventSubscriber extends DefaultExceptionHtmlSubscriber {
  /**
   * {@inheritdoc}
   */
  protected static function getPriority() {
    return 100;
  }

  public function on403(ExceptionEvent $event) {
    $request = $event->getRequest();
    $route_name = $request->attributes->get('_route');

    if (str_starts_with($route_name, 'my_route')) {
      $redirect_url = Url::fromRoute('<front>')
        ->toString();
      $returnResponse = new RedirectResponse($redirect_url);
      $event->setResponse($returnResponse);
    }
  }

  /**
   * {@inheritdoc}
   */
  protected function getHandledFormats() {
    return [];
  }

}

GET some JSON:API or REST resource which throws a 40x exception.
402, 404, 405 will return

: Allowed memory size of 1073741824 bytes exhausted (tried to allocate 69632 bytes) in
on line

401 or 403 error still work.

💬 Support request
Status

Active

Version

10.2

Component
Routing 

Last updated 3 days ago

Created by

🇮🇹Italy Giuseppe87

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024