server: use custom error page

This commit is contained in:
Jeremy Baxter 2026-01-10 21:27:43 +13:00
parent dcb8094403
commit 3bfcf5794f
2 changed files with 49 additions and 23 deletions

View file

@ -31,7 +31,8 @@ type Page interface {
func writePage(p Page, w http.ResponseWriter) {
t, err := template.ParseFS(staticFS, "static/templates/" + p.SourceFile())
if err != nil {
http.Error(w, err.Error(), http.StatusInternalServerError)
http.Error(w, "Internal server error: " + err.Error(),
http.StatusInternalServerError)
return
}
@ -41,6 +42,21 @@ func writePage(p Page, w http.ResponseWriter) {
}
}
type ErrorPage struct {
Status string
Reason string
}
func MakeErrorPage(status, reason string) (p ErrorPage) {
p.Status = status
p.Reason = reason
return
}
func (p ErrorPage) SourceFile() string { return "error.html" }
func (p ErrorPage) Title() string { return "" }
func (p ErrorPage) Body() template.HTML { return template.HTML("") }
type IndexPage struct {
Showcase string
}