From de5393154aa55f53b232afd062bdfdb03e5a7c4d Mon Sep 17 00:00:00 2001 From: Tim Ramlot <42113979+inteon@users.noreply.github.com> Date: Sat, 6 Jan 2024 13:37:38 +0100 Subject: [PATCH] use more specific http error code Signed-off-by: Tim Ramlot <42113979+inteon@users.noreply.github.com> --- pkg/webhook/admission/http.go | 2 +- pkg/webhook/admission/http_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/pkg/webhook/admission/http.go b/pkg/webhook/admission/http.go index 15e408dc43..1121814fc0 100644 --- a/pkg/webhook/admission/http.go +++ b/pkg/webhook/admission/http.go @@ -83,7 +83,7 @@ func (wh *Webhook) ServeHTTP(w http.ResponseWriter, r *http.Request) { if limitedReader.N <= 0 { err := fmt.Errorf("request entity is too large; limit is %d bytes", maxRequestSize) wh.getLogger(nil).Error(err, "unable to read the body from the incoming request; limit reached") - wh.writeResponse(w, Errored(http.StatusBadRequest, err)) + wh.writeResponse(w, Errored(http.StatusRequestEntityTooLarge, err)) return } diff --git a/pkg/webhook/admission/http_test.go b/pkg/webhook/admission/http_test.go index 75517a66f9..86f35ac882 100644 --- a/pkg/webhook/admission/http_test.go +++ b/pkg/webhook/admission/http_test.go @@ -105,7 +105,7 @@ var _ = Describe("Admission Webhooks", func() { Body: nopCloser{Reader: rand.Reader}, } - expected := `{"response":{"uid":"","allowed":false,"status":{"metadata":{},"message":"request entity is too large; limit is 7340032 bytes","code":400}}} + expected := `{"response":{"uid":"","allowed":false,"status":{"metadata":{},"message":"request entity is too large; limit is 7340032 bytes","code":413}}} ` webhook.ServeHTTP(respRecorder, req) Expect(respRecorder.Body.String()).To(Equal(expected))