chore: log rendering errors

This commit is contained in:
Ivan R. 2024-04-01 23:55:43 +05:00
parent 5aa4396148
commit c8f8a7feb4
No known key found for this signature in database
GPG key ID: 56C7BAAE859B302C
3 changed files with 7 additions and 13 deletions

View file

@ -5,7 +5,6 @@ import (
"time" "time"
"github.com/ordinary-dev/phoenix/database" "github.com/ordinary-dev/phoenix/database"
log "github.com/sirupsen/logrus"
) )
func ShowMainPage(w http.ResponseWriter, r *http.Request) { func ShowMainPage(w http.ResponseWriter, r *http.Request) {
@ -38,12 +37,9 @@ func ShowMainPage(w http.ResponseWriter, r *http.Request) {
style = "list" style = "list"
} }
err = Render("index.html.tmpl", w, map[string]any{ Render("index.html.tmpl", w, map[string]any{
"description": "Self-hosted start page.", "description": "Self-hosted start page.",
"groups": groups, "groups": groups,
"style": style, "style": style,
}) })
if err != nil {
log.Error(err)
}
} }

View file

@ -4,22 +4,17 @@ import (
"net/http" "net/http"
"strings" "strings"
log "github.com/sirupsen/logrus"
"github.com/ordinary-dev/phoenix/database" "github.com/ordinary-dev/phoenix/database"
"github.com/ordinary-dev/phoenix/jwttoken" "github.com/ordinary-dev/phoenix/jwttoken"
) )
func ShowSignInForm(w http.ResponseWriter, _ *http.Request) { func ShowSignInForm(w http.ResponseWriter, _ *http.Request) {
err := Render("auth.html.tmpl", w, map[string]any{ Render("auth.html.tmpl", w, map[string]any{
"title": "Sign in", "title": "Sign in",
"description": "Authorization is required to view this page.", "description": "Authorization is required to view this page.",
"button": "Sign in", "button": "Sign in",
"formAction": "/signin", "formAction": "/signin",
}) })
if err != nil {
log.Error(err)
}
} }
func AuthorizeUser(w http.ResponseWriter, r *http.Request) { func AuthorizeUser(w http.ResponseWriter, r *http.Request) {

View file

@ -59,12 +59,15 @@ func LoadTemplates() error {
return nil return nil
} }
func Render(template string, wr io.Writer, data map[string]any) error { func Render(template string, wr io.Writer, data map[string]any) {
data["fontFamily"] = config.Cfg.FontFamily data["fontFamily"] = config.Cfg.FontFamily
if _, ok := data["title"]; !ok { if _, ok := data["title"]; !ok {
data["title"] = config.Cfg.Title data["title"] = config.Cfg.Title
} }
return templates[template].Execute(wr, data) err := templates[template].Execute(wr, data)
if err != nil {
log.WithField("template", template).Error(err)
}
} }