Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: add body to error if we are unable to decode it #815

Merged
merged 1 commit into from
Oct 2, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading