fix(api): convert --data to query params for GET requests#383
Merged
Conversation
Contributor
Semver Impact of This PR🟢 Patch (bug fixes) 📋 Changelog PreviewThis is how your changes will appear in the changelog. New Features ✨Init
Other
Bug Fixes 🐛Init
Other
Internal Changes 🔧Init
Other
🤖 This preview updates automatically when you update the PR. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
When using `sentry api` with `--data` and a GET method (the default), the data was always sent as a request body. The Fetch API spec forbids bodies on GET/HEAD/OPTIONS requests, causing: TypeError: fetch() request with GET/HEAD/OPTIONS method cannot have body. Now `--data` on GET requests converts the data to query parameters: - URL-encoded strings (e.g. `stat=received&resolution=1d`) are parsed via URLSearchParams - JSON objects have their values stringified as query params - JSON arrays throw a clear ValidationError with guidance This matches how `--field`/`--raw-field` already handle GET requests via `prepareRequestOptions()`, and aligns with `gh api` behavior. Fixes CLI-CJ
parseDataBody can return null, booleans, or numbers from JSON.parse (hidden behind an `as` cast). These fall through the string and array checks in dataToQueryParams and crash on Object.entries(null). Guard against all non-object primitives with a clear ValidationError. Extract URL-encoded parsing to a helper to stay under complexity limit.
5db9a4d to
31e7dfd
Compare
Contributor
Codecov Results 📊✅ 104 passed | Total: 104 | Pass Rate: 100% | Execution Time: 0ms 📊 Comparison with Base Branch
✨ No test changes detected All tests are passing successfully. ✅ Patch coverage is 100.00%. Project has 899 uncovered lines. Coverage diff@@ Coverage Diff @@
## main #PR +/-##
==========================================
+ Coverage 95.48% 95.49% +0.01%
==========================================
Files 142 142 —
Lines 19898 19933 +35
Branches 0 0 —
==========================================
+ Hits 18999 19034 +35
- Misses 899 899 —
- Partials 0 0 —Generated by Codecov Action |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
sentry apiwith--dataon a GET request (the default method) threw:The
resolveBody()function always converted--datainto a request body regardless of HTTP method. The Fetch API spec forbids bodies on GET/HEAD/OPTIONS requests.Fix
When
--datais used with a GET request, the data is now converted to query parameters instead of a request body:stat=received&resolution=1d) are parsed viaURLSearchParamsValidationErrorwith guidance to use--method POSTThis matches how
--field/--raw-fieldalready handle GET requests viaprepareRequestOptions(), and aligns withgh apibehavior.Changes
src/commands/api.ts— AddeddataToQueryParams()helper; updatedresolveBody()to route--datathrough it for GET requeststest/commands/api.test.ts— 10 new tests covering the helper andresolveBodyintegrationFixes CLI-CJ