Skip to content

Commit e58d186

Browse files
committed
feat: first implementation for #20
1 parent dcd9121 commit e58d186

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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+
}

src/Views/Errors/403.view.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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>

src/Views/Errors/404.view.php

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
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>

0 commit comments

Comments
 (0)