Catch HTTPExceptions in App::runFrontend()

Set correct http response header, display error message using "404.tpl"
This commit is contained in:
fabrixxm 2018-11-20 22:34:39 +01:00 committed by Hypolite Petovan
parent b96dbcd4cb
commit 89eaf508f1

View file

@ -9,6 +9,7 @@ use DOMDocument;
use DOMXPath;
use Exception;
use Friendica\Database\DBA;
use Friendica\Network\HTTPException;
use Friendica\Network\HTTPException\InternalServerErrorException;
/**
@ -1718,6 +1719,8 @@ class App
}
}
// Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid
try {
$content = '';
// Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid
@ -1774,6 +1777,14 @@ class App
}
$this->page['content'] .= $content;
} catch (HTTPException $e) {
header($_SERVER["SERVER_PROTOCOL"] . " " . $e->httpcode . " " . $e->httpdesc , true, $e->httpcode);
$error = ($e->getMessage() !== "" ? $e->getMessage() : $e->httpdesc);
$tpl = Core\Renderer::getMarkupTemplate("404.tpl");
$this->page['content'] = Core\Renderer::replaceMacros($tpl, [
'$message' => $error
]);
}
/* Create the page head after setting the language
* and getting any auth credentials.