Re-using an existing route in Drupal

For Page Not Found Passthrough module we need to try a bunch of things and then fall back on the existing default 404 not found route if nothing else works.

That route is very nicely defined in core/modules/system/system.routing.yml:

system.404:
  path: '/system/404'
  defaults:
    _controller: '\Drupal\system\Controller\Http4xxController:on404'
    _title: 'Page not found'
  requirements:
    _access: 'TRUE'

I’m looking for a way to effectively load and execute that route, with all those pieces as defined.

I could redirect to the path /system/404 path, but it’s traditional for 404 pages to leave the path that a person was trying to go to intact.

Bah. Spent too long trying to figure out how to directly do things that simply aren’t done anywhere in Drupal. I’m sure it’s possible but i’m no good at spelunking in Symfony or Drupal where this is done at a low level that’s never meant to be done the way i want to do it.

So i just grabbed the controller part directly:

    $default4xxController = new \Drupal\system\Controller\Http4xxController();
    return $default4xxController->on404();

And moved on with my life. Happy to update this if someone finds the better way and tells me!