Implement error handling system
This commit is contained in:
		
							parent
							
								
									cd1e1eb01b
								
							
						
					
					
						commit
						ddaecac0f1
					
				
							
								
								
									
										23
									
								
								Kernel/Exceptions/HTTPSpecialCaseException.php
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										23
									
								
								Kernel/Exceptions/HTTPSpecialCaseException.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										8
									
								
								Views/errors/400.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										3
									
								
								Views/errors/403.php
									
									
									
									
									
										Normal 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
									
								
							
							
						
						
									
										8
									
								
								Views/errors/500.php
									
									
									
									
									
										Normal 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>
 | 
			
		||||
							
								
								
									
										12
									
								
								index.php
									
									
									
									
									
								
							
							
						
						
									
										12
									
								
								index.php
									
									
									
									
									
								
							@ -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();
 | 
			
		||||
 | 
			
		||||
		Loading…
	
		Reference in New Issue
	
	Block a user