Commit 960273fc authored by Ben Abbott's avatar Ben Abbott Committed by Benni Mack
Browse files

[TASK] Change page unavailable status code from 500 to 503

Page unavailable (e.g. maintenance mode) is a "503 service unavailable"
error, not 500 internal server error.
If TYPO3 is in maintenance mode then a 503 error is now thrown.
Also 503 Error Handlers are taken into account now.

Releases: master, 10.4
Resolves: #93032
Change-Id: I8bd013fc202b07263388fc22ec2256262c40b709
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/67074


Tested-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Tested-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
Reviewed-by: Benjamin Franzke's avatarBenjamin Franzke <bfr@qbus.de>
Reviewed-by: Christian Kuhn's avatarChristian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Benni Mack's avatarBenni Mack <benni@typo3.org>
parent cd4227e2
......@@ -36,7 +36,7 @@ use TYPO3\CMS\Core\Utility\GeneralUtility;
class ErrorController
{
/**
* Used for creating a 500 response ("Page unavailable"), usually due some misconfiguration
* Used for creating a 503 response ("Page unavailable"), usually due some misconfiguration
* but if configured, a RedirectResponse could be returned as well.
*
* @param ServerRequestInterface $request
......@@ -50,11 +50,11 @@ class ErrorController
if (!$this->isPageUnavailableHandlerConfigured()) {
throw new ServiceUnavailableException($message, 1518472181);
}
$errorHandler = $this->getErrorHandlerFromSite($request, 500);
$errorHandler = $this->getErrorHandlerFromSite($request, 503);
if ($errorHandler instanceof PageErrorHandlerInterface) {
return $errorHandler->handlePageError($request, $message, $reasons);
}
return $this->handleDefaultError($request, 500, $message ?: 'Page is unavailable');
return $this->handleDefaultError($request, 503, $message ?: 'Page is unavailable');
}
/**
......
......@@ -110,7 +110,7 @@ class ErrorControllerTest extends UnitTestCase
GeneralUtility::addInstance(Typo3Information::class, $typo3InformationProphecy->reveal());
$subject = new ErrorController();
$response = $subject->unavailableAction(new ServerRequest(), 'Error handler is not configured.');
self::assertSame(500, $response->getStatusCode());
self::assertSame(503, $response->getStatusCode());
self::assertSame('text/html; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertStringContainsString('Error handler is not configured.', $response->getBody()->getContents());
}
......@@ -123,7 +123,7 @@ class ErrorControllerTest extends UnitTestCase
$subject = new ErrorController();
$response = $subject->unavailableAction((new ServerRequest())->withAddedHeader('Accept', 'application/json'), 'Error handler is not configured.');
$responseContent = \json_decode($response->getBody()->getContents(), true);
self::assertSame(500, $response->getStatusCode());
self::assertSame(503, $response->getStatusCode());
self::assertSame('application/json; charset=utf-8', $response->getHeaderLine('Content-Type'));
self::assertEquals(['reason' => 'Error handler is not configured.'], $responseContent);
}
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment