No sooner had I posted the question I finally figured this out.
The store is on default mode.
https://github.com/magento/magento2/blob/2.4.2/lib/internal/Magento/Framework/App/StaticResource.php#L163-L186
/**
* @inheritdoc
*/
public function catchException(Bootstrap $bootstrap, \Exception $exception)
{
$this->getLogger()->critical($exception->getMessage());
if ($bootstrap->isDeveloperMode()) {
$this->response->setHttpResponseCode(404);
$this->response->setHeader('Content-Type', 'text/plain');
$this->response->setBody(
$exception->getMessage() . "\n" .
Debug::trace(
$exception->getTrace(),
true,
true,
(bool)getenv('MAGE_DEBUG_SHOW_ARGS')
)
);
$this->response->sendResponse();
} else {
require $this->getFilesystem()->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php');
}
return true;
}
So I'm hitting this part require $this->getFilesystem()->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/404.php');
And checking errors/404.php
https://github.com/magento/magento2/blob/2.4.2/pub/errors/404.php#L11
$response = $processor->process404();
https://github.com/magento/magento2/blob/2.4-develop/pub/errors/processor.php#L209-L220
/**
* Process 404 error
*
* @return \Magento\Framework\App\Response\Http
*/
public function process404()
{
$this->pageTitle = 'Error 404: Not Found';
$this->_response->setHttpResponseCode(404);
$this->_response->setBody($this->_renderPage('404.phtml'));
return $this->_response;
}
This part $this->_response->setHttpResponseCode(404);