moved error page to logging

This commit is contained in:
bronku 2025-03-28 18:12:00 +01:00
parent 93afc14386
commit f8c03173cb
2 changed files with 6 additions and 4 deletions

View file

@ -1,11 +1,11 @@
package server package logging
import ( import (
"fmt" "fmt"
"net/http" "net/http"
) )
func errorPage(err error, status int) http.HandlerFunc { func ErrorPage(err error, status int) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) { return func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(status) w.WriteHeader(status)
fmt.Fprint(w, err.Error()) fmt.Fprint(w, err.Error())

View file

@ -5,6 +5,8 @@ import (
"html/template" "html/template"
"log" "log"
"net/http" "net/http"
"github.com/Bronku/iroon/internal/logging"
) )
//go:embed templates/* //go:embed templates/*
@ -23,12 +25,12 @@ func (s *Server) render(fetch fetcher, templateName string) http.HandlerFunc {
w.Header().Set("content-type", "text/html") w.Header().Set("content-type", "text/html")
data, code, err := fetch(r) data, code, err := fetch(r)
if err != nil { if err != nil {
errorPage(err, code).ServeHTTP(w, r) logging.ErrorPage(err, code).ServeHTTP(w, r)
return return
} }
err = s.tmpl.ExecuteTemplate(w, templateName, data) err = s.tmpl.ExecuteTemplate(w, templateName, data)
if err != nil { if err != nil {
errorPage(err, http.StatusInternalServerError).ServeHTTP(w, r) logging.ErrorPage(err, http.StatusInternalServerError).ServeHTTP(w, r)
} }
} }
} }