mirror of
https://github.com/pomerium/pomerium.git
synced 2025-07-29 14:39:40 +02:00
httputil: remove error details (#3703)
This commit is contained in:
parent
d17599f63b
commit
b51b93dcf3
9 changed files with 33 additions and 33 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
"net/http"
|
||||
"net/url"
|
||||
|
||||
"github.com/pomerium/pomerium/internal/log"
|
||||
"github.com/pomerium/pomerium/internal/telemetry/requestid"
|
||||
"github.com/pomerium/pomerium/pkg/contextutil"
|
||||
"github.com/pomerium/pomerium/ui"
|
||||
|
@ -52,7 +53,6 @@ func (e *HTTPError) ErrorResponse(ctx context.Context, w http.ResponseWriter, r
|
|||
}
|
||||
response := struct {
|
||||
Status int
|
||||
Error string
|
||||
StatusText string `json:"-"`
|
||||
RequestID string `json:",omitempty"`
|
||||
CanDebug bool `json:"-"`
|
||||
|
@ -61,7 +61,6 @@ func (e *HTTPError) ErrorResponse(ctx context.Context, w http.ResponseWriter, r
|
|||
}{
|
||||
Status: e.Status,
|
||||
StatusText: StatusText(e.Status),
|
||||
Error: e.Error(),
|
||||
RequestID: reqID,
|
||||
CanDebug: e.Status/100 == 4 && (e.DebugURL != nil || reqID != ""),
|
||||
DebugURL: e.DebugURL,
|
||||
|
@ -70,6 +69,13 @@ func (e *HTTPError) ErrorResponse(ctx context.Context, w http.ResponseWriter, r
|
|||
// indicate to clients that the error originates from Pomerium, not the app
|
||||
w.Header().Set(HeaderPomeriumResponse, "true")
|
||||
|
||||
log.Error(ctx).
|
||||
Err(e.Err).
|
||||
Int("status", e.Status).
|
||||
Str("status-text", StatusText(e.Status)).
|
||||
Str("request-id", reqID).
|
||||
Msg("httputil: error")
|
||||
|
||||
if r.Header.Get("Accept") == "application/json" {
|
||||
RenderJSON(w, e.Status, response)
|
||||
return
|
||||
|
@ -77,7 +83,6 @@ func (e *HTTPError) ErrorResponse(ctx context.Context, w http.ResponseWriter, r
|
|||
|
||||
m := map[string]any{
|
||||
"canDebug": response.CanDebug,
|
||||
"error": response.Error,
|
||||
"requestId": response.RequestID,
|
||||
"status": response.Status,
|
||||
"statusText": response.StatusText,
|
||||
|
|
|
@ -19,7 +19,7 @@ func TestHTTPError_ErrorResponse(t *testing.T) {
|
|||
wantStatus int
|
||||
wantBody string
|
||||
}{
|
||||
{"404 json", http.StatusNotFound, errors.New("route not known"), "application/json", http.StatusNotFound, "{\"Status\":404,\"Error\":\"Not Found: route not known\"}\n"},
|
||||
{"404 json", http.StatusNotFound, errors.New("route not known"), "application/json", http.StatusNotFound, "{\"Status\":404}\n"},
|
||||
{"404 html", http.StatusNotFound, errors.New("route not known"), "", http.StatusNotFound, ""},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
|
|
|
@ -75,8 +75,8 @@ func TestHandlerFunc_ServeHTTP(t *testing.T) {
|
|||
f HandlerFunc
|
||||
wantBody string
|
||||
}{
|
||||
{"good http error", func(w http.ResponseWriter, r *http.Request) error { return NewError(404, errors.New("404")) }, "{\"Status\":404,\"Error\":\"Not Found: 404\"}\n"},
|
||||
{"good std error", func(w http.ResponseWriter, r *http.Request) error { return errors.New("404") }, "{\"Status\":500,\"Error\":\"Internal Server Error: 404\"}\n"},
|
||||
{"good http error", func(w http.ResponseWriter, r *http.Request) error { return NewError(404, errors.New("404")) }, "{\"Status\":404}\n"},
|
||||
{"good std error", func(w http.ResponseWriter, r *http.Request) error { return errors.New("404") }, "{\"Status\":500}\n"},
|
||||
}
|
||||
for _, tt := range tests {
|
||||
t.Run(tt.name, func(t *testing.T) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue