refactor index.php, set http code, and remove header Location on error 400 and 500

This commit is contained in:
Thomas Rubini 2023-01-24 11:01:36 +01:00
parent f703f9342d
commit f6be185af5
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373

View File

@ -17,6 +17,8 @@
View::openBuffer();
$ret = Utils::RETURN_HTML;
$I_err_httpCode = null;
$S_err_msg = null;
try
{
@ -26,17 +28,29 @@
catch (ControleurException $O_exception)
{
View::openBuffer();
View::show("errors/500", $O_exception->getMsg());
$I_err_httpCode = 500;
$S_err_msg = $O_exception->getMsg();
}
catch (NotFoundException $O_exception)
{
View::openBuffer();
View::show("errors/404");
$I_err_httpCode = 404;
}
catch (HTTPSpecialCaseException $O_exception)
{
View::openBuffer();
View::show("errors/".$O_exception->getHTTPCode(), $O_exception->getMsg());
$I_err_httpCode = $O_exception->getHTTPCode();
$S_err_msg = $O_exception->getMsg();
}
if ($I_err_httpCode !== null) {
http_response_code($I_err_httpCode);
if($I_err_httpCode === 500 || $I_err_httpCode === 400) {
header_remove("Location");
}
View::show("errors/".$I_err_httpCode, $S_err_msg);
}