We set up a custom error page theme by creating a block with the error text and then used the following code within a hook_theme_suggestions_page_alter
implementation to determine when to override the template and show that "Page Not Found" block:
// error page template suggestions
if (!is_null(Drupal::requestStack()->getCurrentRequest()->attributes->get('exception'))) {
$status_code = Drupal::requestStack()->getCurrentRequest()->attributes->get('exception')->getStatusCode();
$suggestions[] = 'page__error';
}
Now it turns out that due to some hosting constraints we need to be able to serve up a version of the "Page Not Found" page with an HTTP status code of 200. So, is it possible to use response()->setStatusCode() within hook_theme_suggestions_page_alter? I was hoping to just override the status code for a single arbitrary route, but so far my attempts to call it from there have been unsuccessful.
Admittedly, it would be a hack to call it there even if I can, but I wanted to check before reverting a bunch of theming code.