Maintenance Mode is not going to 503 Page
-
05-10-2020 - |
Question
Normally when you enter maintenance Mode, Magento is supposed to return a 503
Error, and redirect to a customizable page.
Right now, when I enable maintenance mode, Magento returns a 500 error, and displays the following message:
Unable to proceed: the maintenance mode is enabled.
#0 /root/vendor/magento/framework/App/Bootstrap.php(256): Magento\Framework\App\Bootstrap->assertMaintenance()
#1 /root/index.php(40): Magento\Framework\App\Bootstrap->run(Object(Magento\Framework\App\Http))
#2 {main}
Nothing shows up in Magento or server logs. How can I fix this?
Solution
Probably you have developer mode enabled. If you take a look at vendor/magento/framework/App/Http.php
, method catchException is trying to handle Exception
Unable to proceed: the maintenance mode is enabled.
thrown in vendor/magento/framework/App/Bootstrap.php
. and in the case of developer mode it is supposed to send 500 response code. In production mode handleBootstrapErrors method redirects user to errors/503.php
:
/**
* {@inheritdoc}
*/
public function catchException(Bootstrap $bootstrap, \Exception $exception)
{
$result = $this->handleDeveloperMode($bootstrap, $exception)
|| $this->handleBootstrapErrors($bootstrap, $exception)
|| $this->handleSessionException($exception)
|| $this->handleInitException($exception)
|| $this->handleGenericReport($bootstrap, $exception);
return $result;
}
/**
* Error handler for developer mode
*
* @param Bootstrap $bootstrap
* @param \Exception $exception
* @return bool
*/
private function handleDeveloperMode(Bootstrap $bootstrap, \Exception $exception)
{
if ($bootstrap->isDeveloperMode()) {
if (Bootstrap::ERR_IS_INSTALLED == $bootstrap->getErrorCode()) {
try {
$this->redirectToSetup($bootstrap, $exception);
return true;
} catch (\Exception $e) {
$exception = $e;
}
}
$this->_response->setHttpResponseCode(500);
$this->_response->setHeader('Content-Type', 'text/plain');
$this->_response->setBody($exception->getMessage() . "\n" . $exception->getTraceAsString());
$this->_response->sendResponse();
return true;
}
return false;
}
/**
* Handler for bootstrap errors
*
* @param Bootstrap $bootstrap
* @param \Exception &$exception
* @return bool
*/
private function handleBootstrapErrors(Bootstrap $bootstrap, \Exception &$exception)
{
$bootstrapCode = $bootstrap->getErrorCode();
if (Bootstrap::ERR_MAINTENANCE == $bootstrapCode) {
require $this->_filesystem->getDirectoryRead(DirectoryList::PUB)->getAbsolutePath('errors/503.php');
return true;
}
if (Bootstrap::ERR_IS_INSTALLED == $bootstrapCode) {
try {
$this->redirectToSetup($bootstrap, $exception);
return true;
} catch (\Exception $e) {
$exception = $e;
}
}
return false;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with magento.stackexchange