summaryrefslogtreecommitdiffstats
path: root/lib/private/legacy
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2018-06-26 10:27:43 +0200
committerMorris Jobke <hey@morrisjobke.de>2018-06-26 11:44:24 +0200
commit1399f6bece1ff44c062acb21bf880c9d6eb8695e (patch)
treedafb9c77674fecdab62a85c43277f85186d1d35b /lib/private/legacy
parent8c155cd51cb55c89f16d9bcfcb397d4e784ac108 (diff)
downloadnextcloud-server-1399f6bece1ff44c062acb21bf880c9d6eb8695e.tar.gz
nextcloud-server-1399f6bece1ff44c062acb21bf880c9d6eb8695e.zip
Server exception error pages by default with a 500 status code
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib/private/legacy')
-rw-r--r--lib/private/legacy/template.php34
1 files changed, 5 insertions, 29 deletions
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';
- }
}