Refactor: Centralize template loading and improve error handling

- Introduced helpers.LoadTemplateFiles() for consistent layout + topbar rendering
- Replaced repeated template.ParseFiles() calls across handlers
- Created generic RenderError(w, r, statusCode) helper
- Replaced old Render403 with flexible RenderError
- Updated AdminOnly middleware to render 403 errors with context
- Added 500.html template for graceful panic fallback
- Prepared structure for future error codes (404, 429, etc.)
This commit is contained in:
2025-04-02 09:12:13 +01:00
parent f5653f737d
commit 2498b33a9c
16 changed files with 69 additions and 106 deletions

7
templates/error/429.html Normal file
View File

@@ -0,0 +1,7 @@
{{ define "content" }}
<div class="container py-5 text-center">
<h1 class="text-danger">🚫 Too Many Requests</h1>
<p>Whoa there! You're making requests too quickly. Please slow down and try again in a moment.</p>
<a href="/" class="btn btn-primary mt-3">Back to home</a>
</div>
{{ end }}

14
templates/error/500.html Normal file
View File

@@ -0,0 +1,14 @@
{{ define "content" }}
<div class="container py-5 text-center">
<h1 class="display-4 text-danger">500 - Server Error</h1>
<p class="lead">Something went wrong on our end. We're working to fix it.</p>
<div class="mt-4">
<i class="bi bi-exclamation-triangle-fill text-warning" style="font-size: 3rem;"></i>
</div>
<p class="mt-4 text-muted">Please try again later or contact support if the issue persists.</p>
<a href="/" class="btn btn-primary mt-3">Return to Homepage</a>
</div>
{{ end }}