[BUGFIX] Send header Error 404 in case of page not found errors
authorSteffen Gebert <steffen.gebert@typo3.org>
Wed, 23 Mar 2011 22:03:21 +0000 (23:03 +0100)
committerSusanne Moog <typo3@susannemoog.de>
Wed, 30 Mar 2011 12:56:24 +0000 (14:56 +0200)
If a page is not found, status 404 has to be sent.

Due to a recent change, an Exception is thrown instead of exiting.
As the Exception Handler overwrites the status 404 with a 503, this
code was sent to the client.

Change-Id: Ia6c7686c720863aa80e390c452527cabb338bde3
Resolves: #24945
Reviewed-on: http://review.typo3.org/1245
Reviewed-by: Susanne Moog
Tested-by: Susanne Moog
typo3/sysext/cms/tslib/class.tslib_fe.php

index 9fccf9e..1620457 100644 (file)
                                        $this->pageNotFoundAndExit('The requested page does not exist!');
                                } else {
                                        $message = 'The requested page does not exist!';
-                                       header('HTTP/1.0 404 Page Not Found');
+                                       header(t3lib_utility_Http::HTTP_STATUS_404);
                                        t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
-                                       throw new RuntimeException($message, 1294587208);
+                                       $messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+                                       $messagePage->output();
+                                       exit;
                                }
                        }
                }
                                $this->pageNotFoundAndExit('The requested page does not exist!');
                        } else {
                                $message = 'The requested page does not exist!';
-                               header('HTTP/1.0 404 Page Not Found');
+                               header(t3lib_utility_Http::HTTP_STATUS_404);
                                t3lib_div::sysLog($message, 'cms', t3lib_div::SYSLOG_SEVERITY_ERROR);
-                               throw new RuntimeException($message, 1294587209);
+                               $messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+                               $messagePage->output();
+                               exit;
                        }
                }
 
 
                        // Create response:
                if (gettype($code)=='boolean' || !strcmp($code,1))      {       // Simply boolean; Just shows TYPO3 error page with reason:
-                       throw new RuntimeException('The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : ''), 1294587213);
+                       $message = 'The page did not exist or was inaccessible.' . ($reason ? ' Reason: ' . htmlspecialchars($reason) : '');
+                       $messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+                       $messagePage->output();
+                       exit;
                } elseif (t3lib_div::isFirstPartOfStr($code,'USER_FUNCTION:')) {
                        $funcRef = trim(substr($code,14));
                        $params = array(
                                echo $content;  // Output the content
                        }
                } else {
-                       throw new RuntimeException($reason ? htmlspecialchars($reason) : 'Page cannot be found.', 1294587216);
+                       $message = ($reason ? 'Reason: ' . htmlspecialchars($reason) : 'Page cannot be found.');
+                       $messagePage = t3lib_div::makeInstance('t3lib_message_ErrorpageMessage', $message);
+                       $messagePage->output();
                }
                exit();
        }