How to detect 404 in THEME file I'd like to attach a library to a custom 404 page.  I'd like to do this in my theme file.  How can I know if the current response will be a 404 Page Not Found?
Got it.

In your hook within your theme file:

  $status = \Drupal::requestStack()-&gt;getCurrentRequest()-&gt;attributes-&gt;get('exception');
  if ($status &amp;&amp; $status-&gt;getStatusCode() == 404) {
    $page['#attached']['library'][] = 'themename/notfound';
  }