Skip to content

fix(net/ghttp): report invalid json body errors#4775

Open
puneetdixit200 wants to merge 2 commits into
gogf:masterfrom
puneetdixit200:fix-json-body-parse-errors
Open

fix(net/ghttp): report invalid json body errors#4775
puneetdixit200 wants to merge 2 commits into
gogf:masterfrom
puneetdixit200:fix-json-body-parse-errors

Conversation

@puneetdixit200
Copy link
Copy Markdown

Summary:

  • set request errors when JSON-looking request bodies fail to parse under application/json
  • propagate parse errors through struct binding for request, query, and form params
  • add a regression covering malformed JSON request bodies

Tests:

  • GOMODCACHE=/tmp/gf-gomodcache GOCACHE=/tmp/gf-gocache go test ./net/ghttp -run Test_ParamsInvalidJsonReportsParseError -count=1
  • GOMODCACHE=/tmp/gf-gomodcache GOCACHE=/tmp/gf-gocache go test ./net/ghttp -run 'Test_Params(InvalidJsonReportsParseError|TagDefault|TagIn|_Valid|_Parse|_ParseForm|_ParseQuery)|Test_Params_Get(Query|QueryMap|RequestMap)|Test_Issue4093|Test_Issue4227' -count=1\n- GOMODCACHE=/tmp/gf-gomodcache GOCACHE=/tmp/gf-gocache go test ./net/gclient -run Test_Client_Chain_ContentJson -count=1\n- GOMODCACHE=/tmp/gf-gomodcache GOCACHE=/tmp/gf-gocache go test ./net/ghttp -run Test_ParamsInvalidJsonReportsParseError -race -count=1\n- git diff --check\n\nFixes No error will be reported for illegal JSON requests #4087

Copilot AI review requested due to automatic review settings May 22, 2026 09:27
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Note

Copilot was unable to run its full agentic suite in this review.

This PR improves error propagation for request parameter binding when a request has invalid JSON, and adds a unit test to verify that JSON parse errors are reported instead of falling back to struct validation.

Changes:

  • Propagate request parsing errors earlier in Get*Struct helpers (Request, Query, Form).
  • Detect JSON body unmarshal failures and surface an invalid-parameter error when Content-Type indicates JSON.
  • Add a unit test covering invalid JSON input and expected error messaging.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 5 comments.

Show a summary per file
File Description
net/ghttp/ghttp_z_unit_feature_request_param_test.go Adds a controller + test asserting invalid JSON yields a JSON parse error response
net/ghttp/ghttp_request_param_request.go Early-return r.GetError() from request-struct binding
net/ghttp/ghttp_request_param_query.go Early-return r.GetError() from query-struct binding
net/ghttp/ghttp_request_param_form.go Early-return r.GetError() from form-struct binding
net/ghttp/ghttp_request_param.go Sets request error when JSON unmarshal fails for JSON Content-Type

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread net/ghttp/ghttp_request_param.go Outdated
Comment thread net/ghttp/ghttp_request_param_request.go Outdated
Comment thread net/ghttp/ghttp_request_param_query.go Outdated
Comment thread net/ghttp/ghttp_z_unit_feature_request_param_test.go Outdated
Comment thread net/ghttp/ghttp_z_unit_feature_request_param_test.go Outdated
Copilot AI review requested due to automatic review settings May 23, 2026 17:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Comment thread net/ghttp/ghttp_request_param.go Outdated
Comment thread net/ghttp/ghttp_z_unit_feature_request_param_test.go Outdated
@puneetdixit200 puneetdixit200 force-pushed the fix-json-body-parse-errors branch from 00dc94b to 75220dd Compare May 23, 2026 18:01
Copilot AI review requested due to automatic review settings May 24, 2026 00:38
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Comment thread net/ghttp/ghttp_z_unit_feature_request_param_test.go
Comment thread net/ghttp/ghttp_request_param.go Outdated
Comment thread net/ghttp/ghttp_z_unit_feature_request_param_test.go Outdated
@puneetdixit200 puneetdixit200 force-pushed the fix-json-body-parse-errors branch from 78c73b2 to 3e21639 Compare May 24, 2026 04:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants