From a5082f60e7b03478ced63ff6e29e5d9c321b8c22 Mon Sep 17 00:00:00 2001 From: Caleb Doxsey Date: Mon, 5 Dec 2022 09:00:25 -0700 Subject: [PATCH] httputil: ignore errors < 400 (#3781) --- internal/httputil/errors.go | 14 ++++++++------ internal/httputil/errors_test.go | 1 + 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/internal/httputil/errors.go b/internal/httputil/errors.go index 980664c24..0218f072c 100644 --- a/internal/httputil/errors.go +++ b/internal/httputil/errors.go @@ -69,12 +69,14 @@ 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 e.Status >= 400 { + 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) diff --git a/internal/httputil/errors_test.go b/internal/httputil/errors_test.go index 41018bf40..bc6e8c769 100644 --- a/internal/httputil/errors_test.go +++ b/internal/httputil/errors_test.go @@ -21,6 +21,7 @@ func TestHTTPError_ErrorResponse(t *testing.T) { }{ {"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, ""}, + {"302 found", http.StatusFound, errors.New("redirect"), "", http.StatusFound, ""}, } for _, tt := range tests { t.Run(tt.name, func(t *testing.T) {