fix: return 413 when the announcement body exceeds the size cap

Distinguish the http.MaxBytesReader limit from a malformed body: an
oversized payload now returns 413 Request Entity Too Large instead of a
generic 400.
This commit is contained in:
Dominik Schmidt
2026-07-29 08:46:46 +02:00
parent e29d961be3
commit 9d472290f2
2 changed files with 6 additions and 1 deletions

View File

@@ -170,7 +170,7 @@ var _ = Describe("Service", func() {
s := newStore()
newService(s, true).Set(resp, req)
Expect(resp.Code).To(Equal(http.StatusBadRequest))
Expect(resp.Code).To(Equal(http.StatusRequestEntityTooLarge))
got, _ := s.Get()
Expect(got.BannerText).To(BeEmpty())
})

View File

@@ -143,6 +143,11 @@ func (s Service) Set(w http.ResponseWriter, r *http.Request) {
var body Announcement
if err := json.NewDecoder(http.MaxBytesReader(w, r.Body, _maxBodySize)).Decode(&body); err != nil {
var maxBytesErr *http.MaxBytesError
if errors.As(err, &maxBytesErr) {
w.WriteHeader(http.StatusRequestEntityTooLarge)
return
}
w.WriteHeader(http.StatusBadRequest)
return
}