Skip to content

Commit

Permalink
fix: handle "request body too large" error using type assertion
Browse files Browse the repository at this point in the history
  • Loading branch information
rishitashaw committed Nov 22, 2024
1 parent eddbccd commit c9a4a20
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions modules/caddyhttp/requestbody/requestbody.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {

Check failure on line 98 in modules/caddyhttp/requestbody/requestbody.go

View workflow job for this annotation

GitHub Actions / lint (mac)

S1020: when ok is true, err can't be nil (gosimple)
err = caddyhttp.Error(http.StatusRequestEntityTooLarge, err)
}
}
return
}
Expand Down

0 comments on commit c9a4a20

Please sign in to comment.