Implement error handling system

This commit is contained in:
Thomas Rubini 2023-01-24 09:49:02 +01:00
parent cd1e1eb01b
commit ddaecac0f1
No known key found for this signature in database
GPG Key ID: C7D287C8C1CAC373
5 changed files with 54 additions and 0 deletions

View File

@ -0,0 +1,23 @@
<?php
class HTTPSpecialCaseException extends Exception {
protected $httpCode;
protected $msg;
public function __construct($httpCode, $msg = "")
{
parent::__construct();
$this->httpCode = $httpCode;
$this->msg = $msg;
}
public function getHTTPCode(){
return $this->httpCode;
}
public function getMsg(){
return $this->code;
}
}

8
Views/errors/400.php Normal file
View File

@ -0,0 +1,8 @@
<h1>Error 400</h1>
<h2>Erreur du client 😥</h2>
<?php
if (isset($A_view)) {
echo "<p> message d'erreur: $A_view </p>";
}
?>
<a href="/">Retourner à l'accueil<a>

3
Views/errors/403.php Normal file
View File

@ -0,0 +1,3 @@
<h1>Error 403</h1>
<h2>Vous n'avez pas l'autorisation d'accéder à cette page 😥</h2>
<a href="/">Retourner à l'accueil<a>

8
Views/errors/500.php Normal file
View File

@ -0,0 +1,8 @@
<h1>Error 500</h1>
<h2>Erreur interne du serveur 😥</h2>
<?php
if (isset($A_view)) {
echo "<p> message d'erreur: $A_view </p>";
}
?>
<a href="/">Retourner à l'accueil<a>

View File

@ -25,6 +25,18 @@
{
echo ('An error occured: ' . $O_exception->getMessage());
}
catch (HTTPSpecialCaseException $O_exception)
{
// drop old buffer
View::closeBuffer();
View::openBuffer();
View::show("errors/".$O_exception->getHTTPCode(), $O_exception->getMsg());
$content = View::closeBuffer();
View::show('html', array('body' => $content));
return;
}
$content = View::closeBuffer();