diff --git a/internal/auth/team_web.go b/internal/auth/team_web.go index 3559a5f06..4679aaf91 100644 --- a/internal/auth/team_web.go +++ b/internal/auth/team_web.go @@ -26,7 +26,7 @@ func (h *webHandlers) addTeamHandlers(r *mux.Router) { func (h *webHandlers) newTeam(w http.ResponseWriter, r *http.Request) { org, err := decode.Param("organization_name", r) if err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } @@ -40,7 +40,7 @@ func (h *webHandlers) newTeam(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) createTeam(w http.ResponseWriter, r *http.Request) { var opts CreateTeamOptions if err := decode.All(&opts, r); err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } @@ -51,7 +51,7 @@ func (h *webHandlers) createTeam(w http.ResponseWriter, r *http.Request) { return } if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -62,18 +62,18 @@ func (h *webHandlers) createTeam(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) getTeam(w http.ResponseWriter, r *http.Request) { teamID, err := decode.Param("team_id", r) if err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } team, err := h.svc.GetTeamByID(r.Context(), teamID) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } members, err := h.svc.ListTeamMembers(r.Context(), teamID) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -82,14 +82,14 @@ func (h *webHandlers) getTeam(w http.ResponseWriter, r *http.Request) { // retrieve the list. subject, err := internal.SubjectFromContext(r.Context()) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } var users []*User if subject.CanAccessSite(rbac.ListUsersAction) { users, err = h.svc.ListUsers(r.Context()) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } } @@ -119,13 +119,13 @@ func (h *webHandlers) updateTeam(w http.ResponseWriter, r *http.Request) { UpdateTeamOptions } if err := decode.All(¶ms, r); err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } team, err := h.svc.UpdateTeam(r.Context(), params.TeamID, params.UpdateTeamOptions) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -136,13 +136,13 @@ func (h *webHandlers) updateTeam(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) listTeams(w http.ResponseWriter, r *http.Request) { org, err := decode.Param("organization_name", r) if err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } teams, err := h.svc.ListTeams(r.Context(), org) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -162,18 +162,18 @@ func (h *webHandlers) listTeams(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) deleteTeam(w http.ResponseWriter, r *http.Request) { teamID, err := decode.Param("team_id", r) if err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } team, err := h.svc.GetTeamByID(r.Context(), teamID) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } err = h.svc.DeleteTeam(r.Context(), teamID) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -184,12 +184,12 @@ func (h *webHandlers) deleteTeam(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) addTeamMember(w http.ResponseWriter, r *http.Request) { var params TeamMembershipOptions if err := decode.All(¶ms, r); err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } if err := h.svc.AddTeamMembership(r.Context(), params); err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -200,12 +200,12 @@ func (h *webHandlers) addTeamMember(w http.ResponseWriter, r *http.Request) { func (h *webHandlers) removeTeamMember(w http.ResponseWriter, r *http.Request) { var params TeamMembershipOptions if err := decode.All(¶ms, r); err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } if err := h.svc.RemoveTeamMembership(r.Context(), params); err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } diff --git a/internal/auth/web.go b/internal/auth/web.go index 9ce2a886f..faf66d6b6 100644 --- a/internal/auth/web.go +++ b/internal/auth/web.go @@ -33,13 +33,13 @@ func (h *webHandlers) addHandlers(r *mux.Router) { func (h *webHandlers) listOrganizationUsers(w http.ResponseWriter, r *http.Request) { name, err := decode.Param("name", r) if err != nil { - html.Error(w, err.Error(), http.StatusUnprocessableEntity) + h.Error(w, err.Error(), http.StatusUnprocessableEntity) return } users, err := h.svc.ListOrganizationUsers(r.Context(), name) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } @@ -55,7 +55,7 @@ func (h *webHandlers) listOrganizationUsers(w http.ResponseWriter, r *http.Reque func (h *webHandlers) profileHandler(w http.ResponseWriter, r *http.Request) { user, err := internal.SubjectFromContext(r.Context()) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + h.Error(w, err.Error(), http.StatusInternalServerError) return } h.Render("profile.tmpl", w, struct { diff --git a/internal/authenticator/oauth_authenticator.go b/internal/authenticator/oauth_authenticator.go index e5d7f5cc3..01ae3863f 100644 --- a/internal/authenticator/oauth_authenticator.go +++ b/internal/authenticator/oauth_authenticator.go @@ -34,7 +34,7 @@ func (a *oauthAuthenticator) ResponseHandler(w http.ResponseWriter, r *http.Requ client, err := a.NewClient(r.Context(), token) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } @@ -44,7 +44,7 @@ func (a *oauthAuthenticator) ResponseHandler(w http.ResponseWriter, r *http.Requ // Get cloud user cuser, err := client.GetUser(ctx) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } @@ -52,7 +52,7 @@ func (a *oauthAuthenticator) ResponseHandler(w http.ResponseWriter, r *http.Requ Username: &cuser.Name, }) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } } diff --git a/internal/authenticator/oidc_authenticator.go b/internal/authenticator/oidc_authenticator.go index 2dee72211..c2db57a54 100644 --- a/internal/authenticator/oidc_authenticator.go +++ b/internal/authenticator/oidc_authenticator.go @@ -88,28 +88,28 @@ func (o oidcAuthenticator) ResponseHandler(w http.ResponseWriter, r *http.Reques // Extract the ID Token from OAuth2 token. rawIDToken, ok := token.Extra("id_token").(string) if !ok { - html.Error(w, "id_token missing", http.StatusInternalServerError) + html.Error(w, "id_token missing", http.StatusInternalServerError, false) return } // Parse and verify ID Token payload. idt, err := o.verifier.Verify(r.Context(), rawIDToken) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } // Extract custom claims var claims oidcClaims if err := idt.Claims(&claims); err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } // Get claims user user, err := o.getUserFromClaims(claims) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } @@ -117,7 +117,7 @@ func (o oidcAuthenticator) ResponseHandler(w http.ResponseWriter, r *http.Reques Username: &user.Name, }) if err != nil { - html.Error(w, err.Error(), http.StatusInternalServerError) + html.Error(w, err.Error(), http.StatusInternalServerError, false) return } } diff --git a/internal/http/html/error.go b/internal/http/html/error.go index 64d733fc3..673f9db0b 100644 --- a/internal/http/html/error.go +++ b/internal/http/html/error.go @@ -12,6 +12,7 @@ const errorTemplateContent = `
{{ . }}+
{{ .Error }}