File tree Expand file tree Collapse file tree 3 files changed +82
-0
lines changed
Expand file tree Collapse file tree 3 files changed +82
-0
lines changed Original file line number Diff line number Diff line change 1+ <?php
2+
3+ namespace Happytodev \Cyclone \Controllers ;
4+
5+ use Tempest \View \View ;
6+ use Tempest \Router \Get ;
7+
8+ use function Tempest \view ;
9+ use Tempest \Http \Response ;
10+ use Tempest \Log \Logger ;
11+
12+ class ErrorController
13+
14+ {
15+ public function __construct (
16+ private Logger $ logger ,
17+ ) {}
18+
19+ #[Get('/error/{error} ' )]
20+ public function error (string $ error )
21+ {
22+ if (!in_array ($ error , ['403 ' , '404 ' ])) {
23+ $ this ->logger ->error ("Error not found : $ error " );
24+ throw new \Exception ("Error not found " );
25+ }
26+
27+ return match ($ error ) {
28+ '403 ' => $ this ->error403 (),
29+ '404 ' => $ this ->error404 (),
30+ default => $ this ->defaultError ()
31+ };
32+
33+ }
34+
35+ protected function error403 (): View
36+ {
37+ $ message = "You are not allowed to access this page... " ;
38+ return view (
39+ '../Views/Errors/403.view.php ' ,
40+ title: "Access issue " ,
41+ status: 403 ,
42+ message: $ message
43+ );
44+ }
45+
46+ protected function error404 (): View
47+ {
48+ $ message = "The page you are looking for does not exist... " ;
49+ return view (
50+ '../Views/Errors/404.view.php ' ,
51+ title: "Are you lost? " ,
52+ status: 404 ,
53+ message: $ message
54+ );
55+ }
56+ }
Original file line number Diff line number Diff line change 1+ <x-base >
2+ <div class = " flex flex-col justify-center items-center bg-amber-800 min-w-screen min-h-screen text-[#a8caf7] antialiased" >
3+ <div class = " px-8 container" >
4+ <h1 class = " font-thin text-8xl flex gap-x-1" >
5+ <span class = " text-yellow-500" >HTTP</span >
6+ <span class = " text-amber-500" >{ { $status } } </span >
7+ </h1 >
8+ <h4 >
9+ <span class = " text-2xl uppercase text-yellow-200" >{ { $message } } </span >
10+ </h4 >
11+ </div >
12+ </div >
13+ </x-base >
Original file line number Diff line number Diff line change 1+ <x-base >
2+ <div class = " flex flex-col justify-center items-center bg-pink-900 min-w-screen min-h-screen text-[#a8caf7] antialiased" >
3+ <div class = " px-8 container" >
4+ <h1 class = " font-thin text-8xl flex gap-x-1" >
5+ <span class = " text-pink-700" >HTTP</span >
6+ <span class = " text-pink-500" >{ { $status } } </span >
7+ </h1 >
8+ <h4 >
9+ <span class = " text-2xl uppercase text-pink-200" >{ { $message } } </span >
10+ </h4 >
11+ </div >
12+ </div >
13+ </x-base >
You can’t perform that action at this time.
0 commit comments