Bug #91425

404 Error page content is not being rendered since TYPO3 10.4 LTS

Added by Ricky Mathew Kuruvilla 7 days ago.

Status:
New
Priority:
Should have
Assignee:
-
Category:
Frontend
Target version:
Start date:
2020-05-18
Due date:
% Done:

0%

TYPO3 Version:
10
PHP Version:
7.2
Tags:
errorhandling
Complexity:
easy
Is Regression:
Sprint Focus:

Description

404 Error page content is not being rendered since TYPO3 10.4 LTS, evenif it was working for intermediate TYPO3 10.3 version. When i checked the TYPO3\CMS\Core\Error\PageErrorHandler\PageContentErrorHandler found that content of error handling page is not being sent with the response

  public function handlePageError(ServerRequestInterface $request, string $message, array $reasons = []): ResponseInterface
    {
        try {
            $resolvedUrl = $this->resolveUrl($request, $this->errorHandlerConfiguration['errorContentSource']);
            $content = null;
            if ($resolvedUrl !== (string)$request->getUri()) {
                try {
                    $response = GeneralUtility::makeInstance(RequestFactory::class)->request($resolvedUrl, 'GET');
                } catch (\Exception $e) {
                    throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", reason: ' . $e->getMessage(), 1544172838);
                }
                if ($response->getStatusCode() >= 300) {
                    throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", status code: ' . $response->getStatusCode(), 1544172839);
                }
                return $response->withStatus($this->statusCode);
            }
            $content = 'The error page could not be resolved, as the error page itself is not accessible';
        } catch (InvalidRouteArgumentsException | SiteNotFoundException $e) {
            $content = 'Invalid error handler configuration: ' . $this->errorHandlerConfiguration['errorContentSource'];
        }
        return new HtmlResponse($content, $this->statusCode);
    }

So a workaround like following works for me :

diff -ruN a/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php b/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php
--- a/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php    2020-05-12 12:41:40.000000000 +0200
+++ b/typo3/sysext/core/Classes/Error/PageErrorHandler/PageContentErrorHandler.php    2020-05-18 09:54:04.000000000 +0200
@@ -76,12 +76,19 @@
             if ($resolvedUrl !== (string)$request->getUri()) {
                 try {
                     $response = GeneralUtility::makeInstance(RequestFactory::class)->request($resolvedUrl, 'GET');
+                    //patch for getting content from error handling page
+                    $report = [];
+                    $content = GeneralUtility::getUrl($resolvedUrl, 0, null, $report);
                 } catch (\Exception $e) {
                     throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", reason: ' . $e->getMessage(), 1544172838);
                 }
                 if ($response->getStatusCode() >= 300) {
                     throw new \RuntimeException('Error handler could not fetch error page "' . $resolvedUrl . '", status code: ' . $response->getStatusCode(), 1544172839);
                 }
+                //patch for sending content along with status code
+                if($response->getStatusCode() == 200 && $content != null){
+                    return new HtmlResponse($content, $this->statusCode);
+                }
                 return $response->withStatus($this->statusCode);
             }
             $content = 'The error page could not be resolved, as the error page itself is not accessible';

Also available in: Atom PDF