Use the same code paths to render the browser version of emails

This commit is contained in:
Eli Ribble 2026-01-19 21:21:02 +00:00
parent 1232a7c0ec
commit 42caa77b3e
No known key found for this signature in database
6 changed files with 41 additions and 11 deletions

View file

@ -54,7 +54,7 @@ func FileServer(r chi.Router, path string, root http.FileSystem, embeddedFS embe
// Try to open from local filesystem for development
fileToServe, err = root.Open(requestedPath)
if err != nil {
respondError(w, "Failed to open file", err, http.StatusNotFound)
RespondError(w, "Failed to open file", err, http.StatusNotFound)
return
}
}

View file

@ -85,7 +85,7 @@ func RenderOrError(w http.ResponseWriter, template *BuiltTemplate, context inter
err := template.executeTemplate(buf, context)
if err != nil {
log.Error().Err(err).Strs("files", template.files).Msg("Failed to render template")
respondError(w, "Failed to render template", err, http.StatusInternalServerError)
RespondError(w, "Failed to render template", err, http.StatusInternalServerError)
return
}
buf.WriteTo(w)

View file

@ -34,7 +34,7 @@ func (crw *customResponseWriter) Write(b []byte) (int, error) {
}
// Respond with an error that is visible to the user
func respondError(w http.ResponseWriter, m string, e error, s int) {
func RespondError(w http.ResponseWriter, m string, e error, s int) {
log.Warn().Int("status", s).Err(e).Str("user message", m).Msg("Responding with an error")
http.Error(w, m, s)
}