title: Drupal 8: Intercepting a 404 route and setting to code to 200
body: <p>In a Drupal 8 site, /some/random/path will return "404 not found". At runtime, I need to intercept some of these paths and set them to return something valid. </p>
  
  <p>I added a file called <code>MYMODULE.services.yml</code>:</p>
  
  <pre><code>services:
    mymodule.route_subscriber:
      class: Drupal\MYMODULE\Routing\RouteSubscriber
      tags:
        - { name: event_subscriber }
  </code></pre>
  
  <p>Then, in ./src/Routing/RouteSubscriber.php, I have:</p>
  
  <pre><code>&lt;?php
  namespace Drupal\MYMODULE\Routing;
  
  use Drupal\Core\Routing\RouteSubscriberBase;
  use Symfony\Component\Routing\RouteCollection;
  
  class RouteSubscriber extends RouteSubscriberBase {
    protected function alterRoutes(RouteCollection $collection) {
      if ($route = $collection-&gt;get('system.404')) {
        $route-&gt;setDefault('_controller', '\Drupal\MYMODULE\Controller\MyController::load');
      }
    }
  }
  </code></pre>
  
  <p>Then in ./src/Controller/SpokeController.php, I have:</p>
  
  <pre><code>class SpokeController extends ControllerBase {
  
    public function load() {
      $path = \Drupal::service('path.current')-&gt;getPath();
  
      if (path_is_valid()) { // I can only do this at runtime.
        // Is there a way to add something here like:
        // $this-&gt;setResponseCode(200);
        // return a render array for the content.
      }
      else {
        // return a render array like "page not found".
      }
    }
  
  }
  </code></pre>
  
  <p>In my controller, can I change the response code from 404 to 200? (I am expecting something like <code>$this-&gt;setResponseCode(200)</code> to exist, but I can't find it.)</p>