0

When you are generating static content and you view a link to an asset for example

https://domain/static/version1234/frontend/Vendor/Theme/en_GB/mage/translate.js

If you view the file before it's been generated you see the following error

Service Temporarily Available

And a 404 response code is sent. Refresh after static content process is finished you see the asset and a 200 response code is sent. Does anyone know where the code that sends the 404 response code is set?

1 Answer 1

0

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);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.