Extend the use of exceptions in App::runFrontend

- Replace an explicit header locatiobn + exit with System::externalRedirect
This commit is contained in:
Hypolite Petovan 2019-07-23 20:01:45 -04:00
parent 92c1cbeeec
commit 56afc43b21

View file

@ -12,10 +12,12 @@ use Friendica\Core\Config\Cache\ConfigCache;
use Friendica\Core\Config\Configuration;
use Friendica\Core\Hook;
use Friendica\Core\L10n\L10n;
use Friendica\Core\System;
use Friendica\Core\Theme;
use Friendica\Database\Database;
use Friendica\Database\DBA;
use Friendica\Model\Profile;
use Friendica\Module\Login;
use Friendica\Network\HTTPException;
use Friendica\Util\BaseURL;
use Friendica\Util\ConfigFileLoader;
@ -1001,11 +1003,10 @@ class App
*/
public function runFrontend()
{
try {
// Missing DB connection: ERROR
if ($this->getMode()->has(App\Mode::LOCALCONFIGPRESENT) && !$this->getMode()->has(App\Mode::DBAVAILABLE)) {
Module\Special\HTTPException::rawContent(
new HTTPException\InternalServerErrorException('Apologies but the website is unavailable at the moment.')
);
throw new HTTPException\InternalServerErrorException('Apologies but the website is unavailable at the moment.');
}
// Max Load Average reached: ERROR
@ -1013,17 +1014,13 @@ class App
header('Retry-After: 120');
header('Refresh: 120; url=' . $this->getBaseURL() . "/" . $this->query_string);
Module\Special\HTTPException::rawContent(
new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.')
);
throw new HTTPException\ServiceUnavailableException('The node is currently overloaded. Please try again later.');
}
if (!$this->getMode()->isInstall()) {
// Force SSL redirection
if ($this->baseURL->checkRedirectHttps()) {
header('HTTP/1.1 302 Moved Temporarily');
header('Location: ' . $this->getBaseURL() . '/' . $this->query_string);
exit();
System::externalRedirect($this->getBaseURL() . '/' . $this->query_string);
}
Core\Session::init();
@ -1067,9 +1064,7 @@ class App
// Someone came with an invalid parameter, maybe as a DDoS attempt
// We simply stop processing here
Core\Logger::log("Invalid ZRL parameter " . $_GET['zrl'], Core\Logger::DEBUG);
Module\Special\HTTPException::rawContent(
new HTTPException\ForbiddenException()
);
throw new HTTPException\ForbiddenException();
}
}
}
@ -1225,7 +1220,7 @@ class App
// Initialize module that can set the current theme in the init() method, either directly or via App->profile_uid
$this->page['page_title'] = $this->module;
try {
$placeholder = '';
Core\Hook::callAll($this->module . '_mod_init', $placeholder);