Skip to content

Commit

Permalink
chore: add body to error if we are unable to decode it (#815)
Browse files Browse the repository at this point in the history
  • Loading branch information
aeneasr authored Oct 2, 2024
1 parent ff66036 commit 1f956ac
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions decoderx/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ func (t *HTTP) validateRequest(r *http.Request, c *httpDecoderOptions) error {
}

if method != "GET" {
if r.ContentLength == 0 && method != "GET" {
if r.ContentLength == 0 {
return errors.WithStack(herodot.ErrBadRequest.WithReasonf(`Unable to decode HTTP Request Body because its HTTP Header "Content-Length" is zero.`))
}

Expand Down Expand Up @@ -555,7 +555,7 @@ func (t *HTTP) decodeJSON(r *http.Request, destination interface{}, o *httpDecod

dc := json.NewDecoder(bytes.NewReader(raw))
if err := dc.Decode(destination); err != nil {
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("Unable to decode JSON payload: %s", err))
return errors.WithStack(herodot.ErrBadRequest.WithReasonf("Unable to decode JSON payload: %s", err).WithDebugf("Received request body: %s", string(raw)))
}

if err := t.validatePayload(r.Context(), raw, o); err != nil {
Expand Down

0 comments on commit 1f956ac

Please sign in to comment.