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
parent 36c8828b32
commit 58bd75f8f3

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;
require_once 'boot.php';
@ -1684,6 +1685,7 @@ class App
// Call module functions
if ($this->module_loaded) {
try {
$this->page['page_title'] = $this->module;
$placeholder = '';
@ -1725,6 +1727,14 @@ class App
$func = str_replace('-', '_', $this->getCurrentTheme()) . '_content_loaded';
$func($this);
}
} 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