- Replaced http.Error with helpers.RenderError in Recover middleware - Custom 500.html now rendered with layout and topbar on panic - RenderError gracefully checks template existence and falls back to plain response - Added /account/notifications full view page (index) - Linked "Back to notifications" from notification read view - Fixed typo in template path for notifications/index.html - Improved layout consistency across error and account pages
41 lines
1.0 KiB
Go
41 lines
1.0 KiB
Go
package helpers
|
|
|
|
import (
|
|
"fmt"
|
|
"log"
|
|
"net/http"
|
|
"os"
|
|
"synlotto-website/models"
|
|
)
|
|
|
|
func RenderError(w http.ResponseWriter, r *http.Request, statusCode int) {
|
|
log.Printf("⚙️ RenderError called with status: %d", statusCode)
|
|
|
|
context := TemplateContext(w, r, models.TemplateData{})
|
|
|
|
pagePath := fmt.Sprintf("templates/error/%d.html", statusCode)
|
|
log.Printf("📄 Checking for template file: %s", pagePath)
|
|
|
|
if _, err := os.Stat(pagePath); err != nil {
|
|
log.Printf("🚫 Template file missing: %s", err)
|
|
http.Error(w, http.StatusText(statusCode), statusCode)
|
|
return
|
|
}
|
|
|
|
log.Println("✅ Template file found, loading...")
|
|
|
|
tmpl := LoadTemplateFiles(fmt.Sprintf("%d.html", statusCode), pagePath)
|
|
|
|
w.WriteHeader(statusCode)
|
|
err := tmpl.ExecuteTemplate(w, "layout", context)
|
|
if err != nil {
|
|
log.Printf("❌ Failed to render error page layout: %v", err)
|
|
http.Error(w, http.StatusText(statusCode), statusCode)
|
|
return
|
|
}
|
|
|
|
log.Println("✅ Successfully rendered 500 page")
|
|
}
|
|
|
|
//ToDo Pages.go /template.go to be merged?
|