aboutsummaryrefslogtreecommitdiff
path: root/internal/unsorted/http_template.go
blob: db44e4c4d19a96b86415e99ce542b9ce0e0d3c65 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18

// SPDX-License-Identifier: AGPL-3.0-only
// SPDX-FileCopyrightText: Copyright (c) 2025 Runxi Yu <https://runxiyu.org>

package unsorted

import (
	"log/slog"
	"net/http"
)

// renderTemplate abstracts out the annoyances of reporting template rendering
// errors.
func (s *Server) renderTemplate(w http.ResponseWriter, templateName string, params map[string]any) {
	if err := s.templates.ExecuteTemplate(w, templateName, params); err != nil {
		http.Error(w, "error rendering template: "+err.Error(), http.StatusInternalServerError)
		slog.Error("error rendering template", "error", err.Error())
	}
}