Repository navigation
Conversation
The JSON parser rescued every StandardError and returned the raw body, so a broken JSON stack (e.g. multi_json 1.21 with json 3 raising ArgumentError) looked like a token-less response and get_token reported invalid credentials. Rescue only MultiJson::DecodeError, which exists across multi_json ~> 1.3. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
Contributor
There was a problem hiding this comment.
馃煝 Approval recommended
The focused implementation preserves malformed-body fallback while correctly exposing unexpected parser failures with adequate regression coverage.
0 open findings
What changed in this PR
Narrows JSON error handling so malformed payloads still return raw bodies while unexpected parser failures propagate.
Changes:
- Rescues only
MultiJson::DecodeError. - Adds response and token-flow regression tests.
- Documents the behavior change.
| File | Description |
|---|---|
lib/鈥媜auth2/鈥媟esponse.rb |
Narrows JSON parser rescue behavior. |
spec/鈥媜auth2/鈥媟esponse_spec.rb |
Tests malformed and unexpected parser errors. |
spec/鈥媜auth2/鈥媍lient_spec.rb |
Verifies parser errors propagate through token retrieval. |
CHANGELOG.md |
Records the fix. |
馃 Review effort: Balanced
馃挕 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
This branch has not been deployed
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.
The 1.4 JSON parser is
MultiJson.load(body) rescue body, which catches everyStandardErrorand returns the raw body. That's meant for non-JSON bodies served asapplication/json, but it also hides real failures. Withmulti_json1.21 andjson3,MultiJson.loadraisesArgumentError(JSON.parseno longer accepts a positional options hash). The parser hands back the raw string,get_tokenfinds no token, and the result reads as invalid credentials: in our case, a login redirect loop.This rescues only
MultiJson::DecodeError, so malformed bodies still fall back to the raw string and anything else raises.DecodeErrorexists across the gemspec'smulti_json ~> 1.3range (1.3.0 through 1.21.x, aliased toLoadError/ParseErrorin later versions).get_tokenneeds no change: when no token is built it readsresponse.parsedagain outside its rescue, so the error propagates.I know 1.4 is EOL. This is here in case another 1.4.x release is ever cut, since 1.4 users hit it as soon as
json3 lands in their bundle.