From eddd55bc5dcfe36d8a56645d4b7e2e49429a933c Mon Sep 17 00:00:00 2001 From: Leonardo Bishop Date: Fri, 16 Jan 2026 18:45:03 +0000 Subject: Cache /userinfo for a bit --- web/handler/index.go | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) (limited to 'web/handler/index.go') diff --git a/web/handler/index.go b/web/handler/index.go index 9279151..8b3d43c 100644 --- a/web/handler/index.go +++ b/web/handler/index.go @@ -2,7 +2,7 @@ package handler import ( "html/template" - "log" + "log/slog" "net/http" "git.leonardobishop.net/instancer/pkg/registry" @@ -13,14 +13,20 @@ func GetIndex(tmpl *template.Template, registryClient *registry.RegistryClient) return func(w http.ResponseWriter, r *http.Request) { challenges, err := registryClient.ListRepositories() if err != nil { - log.Printf("Could not list repositories: %v", err) - http.Error(w, "Internal server error", http.StatusInternalServerError) + slog.Error("could not list repositories", "cause", err) + tmpl.ExecuteTemplate(w, "problem.html", struct { + Error string + ShowLogout bool + }{ + Error: "Error occured fetching available challenges. Please try again.", + ShowLogout: false, + }) return } session := r.Context().Value("session").(*session.UserSession) - if err := tmpl.ExecuteTemplate(w, "index.html", struct { + tmpl.ExecuteTemplate(w, "index.html", struct { Challenges []string Name string Team string @@ -28,9 +34,6 @@ func GetIndex(tmpl *template.Template, registryClient *registry.RegistryClient) Challenges: challenges, Name: session.Name, Team: session.TeamName, - }); err != nil { - http.Error(w, "Internal server error", http.StatusInternalServerError) - return - } + }) } } -- cgit v1.2.3-70-g09d2