diff --git a/internal/core/admin.go b/internal/core/admin.go index 40dbfbc..7bdfbb1 100644 --- a/internal/core/admin.go +++ b/internal/core/admin.go @@ -77,7 +77,7 @@ func (s *Handlers) pageAdmin(w http.ResponseWriter, r *http.Request) { func (s *Handlers) pageCatalog(w http.ResponseWriter, r *http.Request) { catalog, err := s.Store.ListCommands(r.Context()) if err != nil { - http.Error(w, "could not load catalog", http.StatusInternalServerError) + s.ServerError(w, r, "could not load catalog", err) return } s.Render(w, r, "admin_catalog.html", map[string]any{ @@ -99,7 +99,7 @@ func (s *Handlers) handleUpdateCommand(w http.ResponseWriter, r *http.Request) { on := func(name string) bool { return r.FormValue(name) != "" } if err := s.Store.UpdateCommandFlags(r.Context(), id, on("risky"), on("share"), on("org_member"), on("org_admin")); err != nil { - http.Error(w, "could not save", http.StatusInternalServerError) + s.ServerError(w, r, "could not save", err) return } http.Redirect(w, r, "/admin/catalog?saved=1", http.StatusSeeOther) @@ -157,7 +157,7 @@ func (s *Handlers) pageUsers(w http.ResponseWriter, r *http.Request) { users, hasMore, err := s.Store.ListUsersPage(r.Context(), p) if err != nil { - http.Error(w, "could not load users", http.StatusInternalServerError) + s.ServerError(w, r, "could not load users", err) return } data := map[string]any{ @@ -217,7 +217,7 @@ func (s *Handlers) handleSetUserCaps(w http.ResponseWriter, r *http.Request) { if target.CapManageUsers { n, err := s.Store.CountManageUsers(r.Context()) if err != nil { - http.Error(w, "error", http.StatusInternalServerError) + s.ServerError(w, r, "could not check administrators", err) return } if n <= 1 { @@ -227,7 +227,7 @@ func (s *Handlers) handleSetUserCaps(w http.ResponseWriter, r *http.Request) { } } if err := s.Store.SetCapabilities(r.Context(), id, manageUsers, manageCatalog); err != nil { - http.Error(w, "could not save", http.StatusInternalServerError) + s.ServerError(w, r, "could not save", err) return } http.Redirect(w, r, "/admin/users", http.StatusSeeOther) @@ -251,7 +251,7 @@ func (s *Handlers) pageUserHistory(w http.ResponseWriter, r *http.Request) { } changes, err := s.Store.ListUsernameChanges(r.Context(), id, usernameHistoryLimit) if err != nil { - http.Error(w, "could not load history", http.StatusInternalServerError) + s.ServerError(w, r, "could not load history", err) return } data := map[string]any{ diff --git a/internal/core/analytics.go b/internal/core/analytics.go index 947931e..6ae0b94 100644 --- a/internal/core/analytics.go +++ b/internal/core/analytics.go @@ -35,27 +35,27 @@ func (s *Handlers) pageAnalytics(w http.ResponseWriter, r *http.Request) { daily, err := s.Store.AnalyticsDaily(r.Context(), days) if err != nil { - http.Error(w, "could not load analytics", http.StatusInternalServerError) + s.ServerError(w, r, "could not load analytics", err) return } surfaces, err := s.Store.AnalyticsBySurface(r.Context(), days) if err != nil { - http.Error(w, "could not load analytics", http.StatusInternalServerError) + s.ServerError(w, r, "could not load analytics", err) return } paths, err := s.Store.AnalyticsTopPaths(r.Context(), days, 20) if err != nil { - http.Error(w, "could not load analytics", http.StatusInternalServerError) + s.ServerError(w, r, "could not load analytics", err) return } hosts, err := s.Store.AnalyticsTopHosts(r.Context(), days, 15) if err != nil { - http.Error(w, "could not load analytics", http.StatusInternalServerError) + s.ServerError(w, r, "could not load analytics", err) return } visitors, err := s.Store.AnalyticsTopVisitors(r.Context(), days, 15) if err != nil { - http.Error(w, "could not load analytics", http.StatusInternalServerError) + s.ServerError(w, r, "could not load analytics", err) return } diff --git a/internal/core/audit.go b/internal/core/audit.go index dfce55e..cc931e0 100644 --- a/internal/core/audit.go +++ b/internal/core/audit.go @@ -17,7 +17,7 @@ func (s *Handlers) pageCommandLog(w http.ResponseWriter, r *http.Request) { } sessions, hasMore, err := s.Store.ListCommandLogSessionsPage(r.Context(), id, decodeLogCursor(r.URL.Query().Get("before"))) if err != nil { - http.Error(w, "could not load log", http.StatusInternalServerError) + s.ServerError(w, r, "could not load log", err) return } data := map[string]any{ diff --git a/internal/core/config_profile.go b/internal/core/config_profile.go index 1f0266d..cbcd992 100644 --- a/internal/core/config_profile.go +++ b/internal/core/config_profile.go @@ -48,7 +48,7 @@ func (s *Handlers) pageOrgConfig(w http.ResponseWriter, r *http.Request) { } role, isMember, err := s.Store.OrgRole(r.Context(), id, uid) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } @@ -64,7 +64,7 @@ func (s *Handlers) pageOrgConfig(w http.ResponseWriter, r *http.Request) { } cv, err := web.BuildConfigView(r.Context(), s.Store, id, r.URL.Query().Get("profile"), latP, lonP) if err != nil { - http.Error(w, "could not load config", http.StatusInternalServerError) + s.ServerError(w, r, "could not load config", err) return } data["Config"] = cv @@ -86,12 +86,12 @@ func (s *Handlers) pageConfigHub(w http.ResponseWriter, r *http.Request) { } profiles, err := s.Store.ListProfiles(r.Context(), orgID) if err != nil { - http.Error(w, "could not load config", http.StatusInternalServerError) + s.ServerError(w, r, "could not load config", err) return } regions, err := s.Store.ListRegions(r.Context(), orgID) if err != nil { - http.Error(w, "could not load config", http.StatusInternalServerError) + s.ServerError(w, r, "could not load config", err) return } var primary string @@ -136,7 +136,7 @@ func (s *Handlers) pageProfileEdit(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not load profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not load profile", err) return } name, stepsText = p.Name, stepsToText(p.Steps) @@ -196,7 +196,7 @@ func (s *Handlers) saveProfile(w http.ResponseWriter, r *http.Request, orgID, pi } catalog, err := s.Store.ListCommands(r.Context()) if err != nil { - http.Error(w, "could not load commands", http.StatusInternalServerError) + s.ServerError(w, r, "could not load commands", err) return } name := strings.TrimSpace(r.FormValue("profile_name")) @@ -220,7 +220,7 @@ func (s *Handlers) saveProfile(w http.ResponseWriter, r *http.Request, orgID, pi http.NotFound(w, r) return case err != nil: - http.Error(w, "could not save profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not save profile", err) return default: http.Redirect(w, r, "/orgs/"+orgParam(r)+"/config/edit", http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin @@ -242,7 +242,7 @@ func (s *Handlers) handleDeleteProfile(w http.ResponseWriter, r *http.Request) { return } if err := s.Store.DeleteProfile(r.Context(), orgID, pid); err != nil && !errors.Is(err, store.ErrNotFound) { - http.Error(w, "could not delete profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not delete profile", err) return } http.Redirect(w, r, "/orgs/"+orgParam(r)+"/config/edit", http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin @@ -261,7 +261,7 @@ func (s *Handlers) pageRegionsEdit(w http.ResponseWriter, r *http.Request) { } regions, err := s.Store.ListRegions(r.Context(), orgID) if err != nil { - http.Error(w, "could not load regions", http.StatusInternalServerError) + s.ServerError(w, r, "could not load regions", err) return } s.Render(w, r, "config_regions_edit.html", map[string]any{ @@ -305,7 +305,7 @@ func (s *Handlers) handleSaveRegions(w http.ResponseWriter, r *http.Request) { return } if err := s.Store.ReplaceRegions(r.Context(), orgID, regions, rootAllowFlood); err != nil { - http.Error(w, "could not save", http.StatusInternalServerError) + s.ServerError(w, r, "could not save", err) return } http.Redirect(w, r, "/orgs/"+orgParam(r)+"/config", http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin diff --git a/internal/core/org_participation.go b/internal/core/org_participation.go index 919724d..b32cac1 100644 --- a/internal/core/org_participation.go +++ b/internal/core/org_participation.go @@ -42,7 +42,7 @@ func (s *Handlers) handleSetRepeaterOrg(w http.ResponseWriter, r *http.Request) } exclude := r.FormValue("action") == "exclude" if err := s.Store.SetRepeaterOrgExcluded(r.Context(), orgID, rep.ID, exclude); err != nil { - http.Error(w, "could not update participation", http.StatusInternalServerError) + s.ServerError(w, r, "could not update participation", err) return } http.Redirect(w, r, sharePath(rep.PublicID), http.StatusSeeOther) @@ -70,7 +70,7 @@ func (s *Handlers) pageOrgCommands(w http.ResponseWriter, r *http.Request) { } ceiling, err := s.orgCeilingCommands(r) if err != nil { - http.Error(w, "could not load commands", http.StatusInternalServerError) + s.ServerError(w, r, "could not load commands", err) return } optIn, _ := s.Store.OrgOptInCommandIDs(r.Context(), id, uid) @@ -115,7 +115,7 @@ func (s *Handlers) handleSaveOrgCommands(w http.ResponseWriter, r *http.Request) // "Remove restriction" clears the list regardless of checkboxes. if r.FormValue("clear") != "" { if err := s.Store.SetOrgOptIn(r.Context(), id, uid, nil); err != nil { - http.Error(w, "could not save", http.StatusInternalServerError) + s.ServerError(w, r, "could not save", err) return } http.Redirect(w, r, "/orgs/"+orgParam(r)+"/my-commands", http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin @@ -123,7 +123,7 @@ func (s *Handlers) handleSaveOrgCommands(w http.ResponseWriter, r *http.Request) } ceiling, err := s.orgCeilingCommands(r) if err != nil { - http.Error(w, "could not load commands", http.StatusInternalServerError) + s.ServerError(w, r, "could not load commands", err) return } chosen := parseCommandIDs(r.Form["cmd"]) @@ -132,7 +132,7 @@ func (s *Handlers) handleSaveOrgCommands(w http.ResponseWriter, r *http.Request) chosen = nil } if err := s.Store.SetOrgOptIn(r.Context(), id, uid, chosen); err != nil { - http.Error(w, "could not save", http.StatusInternalServerError) + s.ServerError(w, r, "could not save", err) return } http.Redirect(w, r, "/orgs/"+orgParam(r)+"/my-commands", http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin diff --git a/internal/core/orgs.go b/internal/core/orgs.go index d08d471..dc8f663 100644 --- a/internal/core/orgs.go +++ b/internal/core/orgs.go @@ -32,7 +32,7 @@ func (s *Handlers) pageMyOrgs(w http.ResponseWriter, r *http.Request) { uid := s.Auth.CurrentUserID(r.Context()) mine, err := s.Store.ListOrgsForUser(r.Context(), uid) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } s.Render(w, r, "my_orgs.html", map[string]any{ @@ -81,7 +81,7 @@ func (s *Handlers) pageOrg(w http.ResponseWriter, r *http.Request) { } role, isMember, err := s.Store.OrgRole(r.Context(), id, uid) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } if !isMember || r.URL.Query().Get("view") == "public" { @@ -95,17 +95,17 @@ func (s *Handlers) pageOrg(w http.ResponseWriter, r *http.Request) { } members, err := s.Store.ListOrgMembers(r.Context(), id) if err != nil { - http.Error(w, "could not load members", http.StatusInternalServerError) + s.ServerError(w, r, "could not load members", err) return } repeaters, err := s.Store.ListOrgRepeaters(r.Context(), id) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } links, err := s.Store.ListOrgLinks(r.Context(), id) if err != nil { - http.Error(w, "could not load links", http.StatusInternalServerError) + s.ServerError(w, r, "could not load links", err) return } mapped := 0 @@ -150,22 +150,22 @@ func (s *Handlers) pageOrg(w http.ResponseWriter, r *http.Request) { func (s *Handlers) renderOrgPublic(w http.ResponseWriter, r *http.Request, org *store.Org, isMember, isAdmin bool) { admins, err := s.Store.ListOrgAdmins(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } memberCount, repeaterCount, err := s.Store.OrgCounts(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } pubReps, err := s.Store.ListPublicRepeaters(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } links, err := s.Store.ListOrgLinks(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } uid := s.Auth.CurrentUserID(r.Context()) @@ -204,7 +204,7 @@ func (s *Handlers) pageOrgMembers(w http.ResponseWriter, r *http.Request) { } role, isMember, err := s.Store.OrgRole(r.Context(), id, uid) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } if !isMember { @@ -213,7 +213,7 @@ func (s *Handlers) pageOrgMembers(w http.ResponseWriter, r *http.Request) { } members, err := s.Store.ListOrgMembers(r.Context(), id) if err != nil { - http.Error(w, "could not load members", http.StatusInternalServerError) + s.ServerError(w, r, "could not load members", err) return } s.Render(w, r, "org_members.html", map[string]any{ @@ -243,12 +243,12 @@ func (s *Handlers) pageOrgRepeaters(w http.ResponseWriter, r *http.Request) { } role, isMember, err := s.Store.OrgRole(r.Context(), id, uid) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } rv, err := web.BuildRepeatersView(r.Context(), s.Store, id, isMember) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } s.Render(w, r, "org_repeaters.html", map[string]any{ @@ -430,7 +430,7 @@ func (s *Handlers) pageJoinOrg(w http.ResponseWriter, r *http.Request) { } _, isMember, err := s.Store.OrgRole(r.Context(), id, uid) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } if isMember { @@ -439,7 +439,7 @@ func (s *Handlers) pageJoinOrg(w http.ResponseWriter, r *http.Request) { } hasRepeaters, err := s.Store.OwnsAnyRepeater(r.Context(), uid) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } s.Render(w, r, "join_org.html", map[string]any{"Org": org, "HasRepeaters": hasRepeaters}) diff --git a/internal/core/registry.go b/internal/core/registry.go index ee1aab1..5a06e42 100644 --- a/internal/core/registry.go +++ b/internal/core/registry.go @@ -62,7 +62,7 @@ func (s *Handlers) pageRepeaterMaintenance(w http.ResponseWriter, r *http.Reques } entries, err := s.Store.ListMaintenance(r.Context(), id) if err != nil { - http.Error(w, "could not load maintenance history", http.StatusInternalServerError) + s.ServerError(w, r, "could not load maintenance history", err) return } isOwner := !rep.Shared diff --git a/internal/core/repeater_setup.go b/internal/core/repeater_setup.go index e1f68d9..80aa0bc 100644 --- a/internal/core/repeater_setup.go +++ b/internal/core/repeater_setup.go @@ -78,7 +78,7 @@ func (s *Handlers) handleSetupCommands(w http.ResponseWriter, r *http.Request) { if req.Profile != "" { s2, err := s.profileSteps(r.Context(), req.OrgID, req.Profile) if err != nil { - http.Error(w, "could not load profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not load profile", err) return } steps = s2 @@ -95,12 +95,12 @@ func (s *Handlers) handleSetupCommands(w http.ResponseWriter, r *http.Request) { } regions, err := s.Store.ListRegions(r.Context(), req.OrgID) if err != nil { - http.Error(w, "could not load regions", http.StatusInternalServerError) + s.ServerError(w, r, "could not load regions", err) return } rootAllow, err := s.Store.RootAllowFlood(r.Context(), req.OrgID) if err != nil { - http.Error(w, "could not load regions", http.StatusInternalServerError) + s.ServerError(w, r, "could not load regions", err) return } cmds = append(cmds, store.RegionDefCommands(regions, rootAllow, req.Lat, req.Lon)...) @@ -255,7 +255,7 @@ func (s *Handlers) handleSetupComplete(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not add repeater", http.StatusInternalServerError) + s.ServerError(w, r, "could not add repeater", err) return } diff --git a/internal/core/repeaters.go b/internal/core/repeaters.go index 7d3e565..c6d5b01 100644 --- a/internal/core/repeaters.go +++ b/internal/core/repeaters.go @@ -123,7 +123,7 @@ func (s *Handlers) pageRepeater(w http.ResponseWriter, r *http.Request) { if isOwner { orgs, err := s.Store.ListRepeaterOrgs(r.Context(), id) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } data["Orgs"] = orgs @@ -152,7 +152,7 @@ func (s *Handlers) pageRepeaterAdded(w http.ResponseWriter, r *http.Request) { } orgs, err := s.Store.ListOrgsForUser(r.Context(), uid) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } s.Render(w, r, "repeater_added.html", map[string]any{ diff --git a/internal/core/shares.go b/internal/core/shares.go index 1a791fd..a73fcc6 100644 --- a/internal/core/shares.go +++ b/internal/core/shares.go @@ -22,19 +22,19 @@ func (s *Handlers) pageShare(w http.ResponseWriter, r *http.Request) { } shares, err := s.Store.ListShares(r.Context(), id) if err != nil { - http.Error(w, "could not load shares", http.StatusInternalServerError) + s.ServerError(w, r, "could not load shares", err) return } invites, err := s.Store.ListInvites(r.Context(), id) if err != nil { - http.Error(w, "could not load links", http.StatusInternalServerError) + s.ServerError(w, r, "could not load links", err) return } // Organizations section: every org the owner belongs to, with whether this // repeater participates (the default) or has been opted out. orgs, err := s.Store.ListRepeaterOrgMemberships(r.Context(), id) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } s.Render(w, r, "share.html", map[string]any{ @@ -139,7 +139,7 @@ func (s *Handlers) pageInvite(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not load invite", http.StatusInternalServerError) + s.ServerError(w, r, "could not load invite", err) return } @@ -153,7 +153,7 @@ func (s *Handlers) pageInvite(w http.ResponseWriter, r *http.Request) { default: shared, err := s.Store.IsShared(r.Context(), rep.ID, uid) if err != nil { - http.Error(w, "could not check access", http.StatusInternalServerError) + s.ServerError(w, r, "could not check access", err) return } if shared { @@ -177,7 +177,7 @@ func (s *Handlers) handleAcceptInvite(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not load invite", http.StatusInternalServerError) + s.ServerError(w, r, "could not load invite", err) return } // Don't consume a single-use link for the owner or someone who already has @@ -196,12 +196,12 @@ func (s *Handlers) handleAcceptInvite(w http.ResponseWriter, r *http.Request) { s.Render(w, r, "invite.html", map[string]any{"State": "invalid"}) return } else if err != nil { - http.Error(w, "could not accept invite", http.StatusInternalServerError) + s.ServerError(w, r, "could not accept invite", err) return } added, err := s.Store.AddShare(r.Context(), rep.ID, uid) if err != nil { - http.Error(w, "could not accept invite", http.StatusInternalServerError) + s.ServerError(w, r, "could not accept invite", err) return } if added { @@ -265,7 +265,7 @@ func (s *Handlers) pageShareCommands(w http.ResponseWriter, r *http.Request) { } catalog, err := s.Store.ListCommands(r.Context()) if err != nil { - http.Error(w, "could not load commands", http.StatusInternalServerError) + s.ServerError(w, r, "could not load commands", err) return } ids, _ := s.Store.ListShareCommandIDs(r.Context(), id, targetID) @@ -306,7 +306,7 @@ func (s *Handlers) handleSetShareCommands(w http.ResponseWriter, r *http.Request } } if err := s.Store.SetShareCommands(r.Context(), id, targetID, cmdIDs); err != nil { - http.Error(w, "could not save commands", http.StatusInternalServerError) + s.ServerError(w, r, "could not save commands", err) return } http.Redirect(w, r, sharePath(repeaterParam(r)), http.StatusSeeOther) //nolint:gosec // G710: local path or config-pinned origin @@ -344,7 +344,7 @@ func (s *Handlers) loadRepeater(w http.ResponseWriter, r *http.Request, return nil, 0, false } if err != nil { - http.Error(w, "could not load repeater", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeater", err) return nil, 0, false } return rep, id, true diff --git a/internal/core/web.go b/internal/core/web.go index 40239e8..ddf8ff5 100644 --- a/internal/core/web.go +++ b/internal/core/web.go @@ -215,12 +215,12 @@ func (s *Handlers) pageRepeaters(w http.ResponseWriter, r *http.Request) { uid := s.Auth.CurrentUserID(r.Context()) repeaters, err := s.Store.ListRepeatersForUser(r.Context(), uid) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } shareCounts, err := s.Store.RepeaterSharingCounts(r.Context(), uid) if err != nil { - http.Error(w, "could not load sharing", http.StatusInternalServerError) + s.ServerError(w, r, "could not load sharing", err) return } owned, shared := splitOwnedShared(repeaters) @@ -253,24 +253,24 @@ func (s *Handlers) pageDashboard(w http.ResponseWriter, r *http.Request) { repeaters, err := s.Store.ListRepeatersForUser(ctx, uid) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } owned, shared := splitOwnedShared(repeaters) orgs, err := s.Store.ListOrgsForUser(ctx, uid) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } recent, err := s.Store.ListRecentCommandsForOwner(ctx, uid, 8) if err != nil { - http.Error(w, "could not load activity", http.StatusInternalServerError) + s.ServerError(w, r, "could not load activity", err) return } user, err := s.Store.GetUserByID(ctx, uid) if err != nil { - http.Error(w, "could not load account", http.StatusInternalServerError) + s.ServerError(w, r, "could not load account", err) return } @@ -315,13 +315,13 @@ func (s *Handlers) pageDashboard(w http.ResponseWriter, r *http.Request) { // they set a primary contact link. publicRole, err := s.Store.UserHasPublicRole(ctx, uid) if err != nil { - http.Error(w, "could not load account", http.StatusInternalServerError) + s.ServerError(w, r, "could not load account", err) return } if publicRole { links, err := s.Store.ListUserLinks(ctx, uid) if err != nil { - http.Error(w, "could not load account", http.StatusInternalServerError) + s.ServerError(w, r, "could not load account", err) return } steps = append(steps, onboardingStep{ diff --git a/internal/marketing/orgs.go b/internal/marketing/orgs.go index d97e944..f3c2475 100644 --- a/internal/marketing/orgs.go +++ b/internal/marketing/orgs.go @@ -41,7 +41,7 @@ func (s *Handlers) pageOrgs(w http.ResponseWriter, r *http.Request) { all, hasMore, err := s.Store.ListPublicOrgsPage(r.Context(), p) if err != nil { - http.Error(w, "could not load organizations", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organizations", err) return } data := map[string]any{ @@ -65,22 +65,22 @@ func (s *Handlers) pageOrgs(w http.ResponseWriter, r *http.Request) { func (s *Handlers) renderOrgPublic(w http.ResponseWriter, r *http.Request, org *store.Org, isMember, isAdmin bool) { admins, err := s.Store.ListOrgAdmins(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } memberCount, repeaterCount, err := s.Store.OrgCounts(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } pubReps, err := s.Store.ListPublicRepeaters(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } links, err := s.Store.ListOrgLinks(r.Context(), org.ID) if err != nil { - http.Error(w, "could not load organization", http.StatusInternalServerError) + s.ServerError(w, r, "could not load organization", err) return } uid := s.Auth.CurrentUserID(r.Context()) @@ -123,7 +123,7 @@ func (s *Handlers) pageOrgConfig(w http.ResponseWriter, r *http.Request) { } cv, err := web.BuildConfigView(r.Context(), s.Store, id, r.URL.Query().Get("profile"), latP, lonP) if err != nil { - http.Error(w, "could not load profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not load profile", err) return } data["Config"] = cv @@ -146,12 +146,12 @@ func (s *Handlers) pageOrgRepeaters(w http.ResponseWriter, r *http.Request) { afterName, afterID := decodeRepCursor(r.URL.Query().Get("cursor")) reps, hasMore, err := s.Store.ListPublicRepeatersPage(r.Context(), id, afterName, afterID) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } points, err := s.Store.ListPublicRepeaterPoints(r.Context(), id) if err != nil { - http.Error(w, "could not load repeaters", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeaters", err) return } rv := web.RepeatersView{Repeaters: reps, MapPoints: points, HasMap: len(points) > 0, Full: false} diff --git a/internal/marketing/repeaters.go b/internal/marketing/repeaters.go index 2aa794f..7a7646b 100644 --- a/internal/marketing/repeaters.go +++ b/internal/marketing/repeaters.go @@ -23,12 +23,12 @@ func (s *Handlers) pageRepeaterPublic(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not load repeater", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeater", err) return } stewards, err := s.Store.ListStewards(r.Context(), rep.ID) if err != nil { - http.Error(w, "could not load repeater", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeater", err) return } radio := fmt.Sprintf("%g MHz / %g kHz / SF%d / CR%d", @@ -47,7 +47,7 @@ func (s *Handlers) pageRepeaterPublic(w http.ResponseWriter, r *http.Request) { } orgs, err := s.Store.ListRepeaterOrgs(r.Context(), rep.ID) if err != nil { - http.Error(w, "could not load repeater", http.StatusInternalServerError) + s.ServerError(w, r, "could not load repeater", err) return } s.Render(w, r, "repeater_public.html", map[string]any{ diff --git a/internal/marketing/users.go b/internal/marketing/users.go index 0501aa2..93ea220 100644 --- a/internal/marketing/users.go +++ b/internal/marketing/users.go @@ -33,12 +33,12 @@ func (s *Handlers) pageUserPublic(w http.ResponseWriter, r *http.Request) { return } if err != nil { - http.Error(w, "could not load profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not load profile", err) return } links, err := s.Store.ListUserLinks(r.Context(), u.ID) if err != nil { - http.Error(w, "could not load profile", http.StatusInternalServerError) + s.ServerError(w, r, "could not load profile", err) return } views := make([]linkView, 0, len(links))