diff options
author | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 11:27:43 +0300 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2018-06-26 12:44:24 +0300 |
commit | 1399f6bece1ff44c062acb21bf880c9d6eb8695e (patch) | |
tree | dafb9c77674fecdab62a85c43277f85186d1d35b /lib | |
parent | 8c155cd51cb55c89f16d9bcfcb397d4e784ac108 (diff) |
Server exception error pages by default with a 500 status code
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 3 | ||||
-rw-r--r-- | lib/private/legacy/template.php | 34 |
2 files changed, 6 insertions, 31 deletions
diff --git a/lib/base.php b/lib/base.php index 54cbc700ec3..60a4c03bc41 100644 --- a/lib/base.php +++ b/lib/base.php @@ -434,8 +434,7 @@ class OC { } catch (Exception $e) { \OC::$server->getLogger()->logException($e, ['app' => 'base']); //show the user a detailed error page - OC_Response::setStatus(OC_Response::STATUS_INTERNAL_SERVER_ERROR); - OC_Template::printExceptionErrorPage($e); + OC_Template::printExceptionErrorPage($e, \OC_Response::STATUS_INTERNAL_SERVER_ERROR); die(); } diff --git a/lib/private/legacy/template.php b/lib/private/legacy/template.php index 4e89b18c144..f84d6386deb 100644 --- a/lib/private/legacy/template.php +++ b/lib/private/legacy/template.php @@ -304,9 +304,10 @@ class OC_Template extends \OC\Template\Base { * Print a fatal error page and terminates the script * @param string $error_msg The error message to show * @param string $hint An optional hint message - needs to be properly escape + * @param int $statusCode * @suppress PhanAccessMethodInternal */ - public static function printErrorPage( $error_msg, $hint = '', $statusCode = \OC_Response::STATUS_INTERNAL_SERVER_ERROR ) { + public static function printErrorPage( $error_msg, $hint = '', $statusCode = 500) { if (\OC::$server->getAppManager()->isEnabledForUser('theming') && !\OC_App::isAppLoaded('theming')) { \OC_App::loadApp('theming'); } @@ -337,11 +338,12 @@ class OC_Template extends \OC\Template\Base { /** * print error page using Exception details * @param Exception|Throwable $exception - * @param bool $fetchPage + * @param int $statusCode * @return bool|string * @suppress PhanAccessMethodInternal */ - public static function printExceptionErrorPage($exception, $fetchPage = false) { + public static function printExceptionErrorPage($exception, $statusCode = 503) { + http_response_code($statusCode); try { $request = \OC::$server->getRequest(); $content = new \OC_Template('', 'exception', 'error', false); @@ -354,16 +356,12 @@ class OC_Template extends \OC\Template\Base { $content->assign('debugMode', \OC::$server->getSystemConfig()->getValue('debug', false)); $content->assign('remoteAddr', $request->getRemoteAddress()); $content->assign('requestID', $request->getId()); - if ($fetchPage) { - return $content->fetchPage(); - } $content->printPage(); } catch (\Exception $e) { $logger = \OC::$server->getLogger(); $logger->logException($exception, ['app' => 'core']); $logger->logException($e, ['app' => 'core']); - header(self::getHttpProtocol() . ' 500 Internal Server Error'); header('Content-Type: text/plain; charset=utf-8'); print("Internal Server Error\n\n"); print("The server encountered an internal error and was unable to complete your request.\n"); @@ -372,26 +370,4 @@ class OC_Template extends \OC\Template\Base { } die(); } - - /** - * This is only here to reduce the dependencies in case of an exception to - * still be able to print a plain error message. - * - * Returns the used HTTP protocol. - * - * @return string HTTP protocol. HTTP/2, HTTP/1.1 or HTTP/1.0. - * @internal Don't use this - use AppFramework\Http\Request->getHttpProtocol instead - */ - protected static function getHttpProtocol() { - $claimedProtocol = strtoupper($_SERVER['SERVER_PROTOCOL']); - $validProtocols = [ - 'HTTP/1.0', - 'HTTP/1.1', - 'HTTP/2', - ]; - if(in_array($claimedProtocol, $validProtocols, true)) { - return $claimedProtocol; - } - return 'HTTP/1.1'; - } } |