Add error page

This commit is contained in:
Eduard Gert
2026-02-04 15:11:22 +01:00
parent ca33849f31
commit 5da2b0fdcc
12 changed files with 106 additions and 22 deletions

View File

@@ -37,7 +37,8 @@ func init() {
// ServeHTTP serves the web UI. For static assets it serves them directly,
// for other paths it renders the page with the provided data.
func ServeHTTP(w http.ResponseWriter, r *http.Request, data any) {
// Optional statusCode can be passed to set a custom HTTP status code (default 200).
func ServeHTTP(w http.ResponseWriter, r *http.Request, data any, statusCode ...int) {
if initErr != nil {
http.Error(w, initErr.Error(), http.StatusInternalServerError)
return
@@ -101,5 +102,8 @@ func ServeHTTP(w http.ResponseWriter, r *http.Request, data any) {
}
w.Header().Set("Content-Type", "text/html")
if len(statusCode) > 0 {
w.WriteHeader(statusCode[0])
}
w.Write(buf.Bytes())
}