From c9a4a20141e53b24043505fcb56f3e62782db680 Mon Sep 17 00:00:00 2001 From: Rishita Shaw Date: Fri, 22 Nov 2024 21:31:50 +0530 Subject: [PATCH] fix: handle "request body too large" error using type assertion --- modules/caddyhttp/requestbody/requestbody.go | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/modules/caddyhttp/requestbody/requestbody.go b/modules/caddyhttp/requestbody/requestbody.go index 1c804aa134a..a2c577091e4 100644 --- a/modules/caddyhttp/requestbody/requestbody.go +++ b/modules/caddyhttp/requestbody/requestbody.go @@ -94,8 +94,10 @@ type errorWrapper struct { func (ew errorWrapper) Read(p []byte) (n int, err error) { n, err = ew.ReadCloser.Read(p) - if err != nil && err.Error() == "http: request body too large" { - err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err) + if err != nil { + if _, ok := err.(*http.MaxBytesError); ok { + err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err) + } } return }