httputil: ignore errors < 400 (#3781)

This commit is contained in:
Caleb Doxsey 2022-12-05 09:00:25 -07:00 committed by GitHub
parent 090601873f
commit a5082f60e7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 9 additions and 6 deletions

View file

@ -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)

View file

@ -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) {