error modals are so on

This commit is contained in:
2026-01-26 12:39:37 +11:00
parent eccab815ae
commit ad6b00e722
19 changed files with 195 additions and 605 deletions

View File

@@ -7,25 +7,6 @@ import (
"git.haelnorr.com/h/oslstats/internal/view/page"
)
// func ErrorPage(
// error hws.HWSError,
// ) (hws.ErrorPage, error) {
// messages := map[int]string{
// 400: "The request you made was malformed or unexpected.",
// 401: "You need to login to view this page.",
// 403: "You do not have permission to view this page.",
// 404: "The page or resource you have requested does not exist.",
// 500: `An error occured on the server. Please try again, and if this
// continues to happen contact an administrator.`,
// 503: "The server is currently down for maintenance and should be back soon. =)",
// }
// msg, exists := messages[error.StatusCode]
// if !exists {
// return nil, errors.New("No valid message for the given code")
// }
// return page.Error(error.StatusCode, http.StatusText(error.StatusCode), msg), nil
// }
func ErrorPage(hwsError hws.HWSError) (hws.ErrorPage, error) {
// Determine if this status code should show technical details
showDetails := shouldShowDetails(hwsError.StatusCode)
@@ -40,7 +21,7 @@ func ErrorPage(hwsError hws.HWSError) (hws.ErrorPage, error) {
// Get technical details if applicable
var details string
if showDetails && hwsError.Error != nil {
details = hwsError.Error.Error()
details = formatErrorDetails(hwsError.Error)
}
// Render appropriate template
@@ -63,7 +44,7 @@ func ErrorPage(hwsError hws.HWSError) (hws.ErrorPage, error) {
// shouldShowDetails determines if a status code should display technical details
func shouldShowDetails(statusCode int) bool {
switch statusCode {
case 400, 500, 503: // Bad Request, Internal Server Error, Service Unavailable
case 400, 418, 500, 503: // Bad Request, Internal Server Error, Service Unavailable
return true
case 401, 403, 404: // Unauthorized, Forbidden, Not Found
return false
@@ -80,6 +61,7 @@ func getDefaultMessage(statusCode int) string {
401: "You need to login to view this page.",
403: "You do not have permission to view this page.",
404: "The page or resource you have requested does not exist.",
418: "I'm a teapot!",
500: `An error occurred on the server. Please try again, and if this
continues to happen contact an administrator.`,
503: "The server is currently down for maintenance and should be back soon. =)",