Refactor: Fetch handler to return status code

This commit is contained in:
bronku 2025-03-22 23:53:38 +01:00
parent a7bd1478bf
commit 47323b32f8
4 changed files with 13 additions and 12 deletions

View file

@ -18,9 +18,9 @@ func (h *Server) loadTemplates() error {
func (s *Server) render(fetch fetcher, templateName string) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("content-type", "text/html")
data, err := fetch(r)
data, code, err := fetch(r)
if err != nil {
errorPage(err, http.StatusInternalServerError).ServeHTTP(w, r)
errorPage(err, code).ServeHTTP(w, r)
return
}
err = s.tmpl.ExecuteTemplate(w, templateName, data)