CodeIgniter Forums
Custom error exception like PageNotFoundException - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Custom error exception like PageNotFoundException (/showthread.php?tid=75242)



Custom error exception like PageNotFoundException - XTAZ - 01-16-2020

Hello!

I need function to show 403 error in CI like throw \CodeIgniter\Exceptions\ForbiddenException::forbidden();

I created own exception handler, but if I replace protected $code = 404; to protected $code = 403; I getted error page instead page like 404.

How can I create a handler?

Or I needs use function with exit method like this?
PHP Code:
function show_forbidden()
{
    
header('HTTP/1.0 403 Forbidden');
    echo 
view('forbidden_page');
    exit;




RE: Custom error exception like PageNotFoundException - InsiteFX - 01-16-2020

SEE: Lonnie's Myth/Auth and look at how he is adding Exceptions in to an Exceptions folder.

Myth:Auth