handle non json jtoken#52
Conversation
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughThe PR bumps the package to 1.9.0 and changes JToken return-format handling: when the server response is non-JSON, the code now returns the raw response body string (preserving the HTTP status code) instead of throwing a JSON parse exception. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~30 minutes Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (3)
Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs (1)
271-292:⚠️ Potential issue | 🟡 MinorPlease add a regression for the new parse-fallback branch.
These tests cover explicit non-JSON content types and valid JSON, but they never hit
Request.csLines 226-230 whereJToken.Parsefails and the code falls back to a raw string. That branch is part of the new behavior and should be pinned too.As per coding guidelines,
Frends.*/Frends.*.Tests/*: Confirm unit tests exist and provide at least 80% coverage.Also applies to: 438-457
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs` around lines 271 - 292, Add a unit test that exercises the parse-fallback branch in Request.cs (around lines 226-230) by simulating a response whose Content-Type suggests JSON (e.g., "application/json") but whose body is invalid JSON so JToken.Parse throws; in the test (e.g., alongside RestRequest_NonJsonResponse_ShouldReturnRawStringInsteadOfThrowing in Frends.HTTP.Request.Tests/UnitTests.cs) call HTTP.Request with headers containing application/json, a response body that is not valid JSON, and assert that result.Body is a string (ClassicAssert.IsInstanceOf<string>), that the string contains the original raw response content, and that result.StatusCode equals the expected code (e.g., 200), thereby pinning the fallback behavior.Frends.HTTP.Request/Frends.HTTP.Request/Request.cs (2)
62-66:⚠️ Potential issue | 🔴 CriticalUpdate the Result class to include required properties before merging.
The
Resultclass is missing required properties per coding guidelines. Add:
Success(bool) propertyErrorobject withMessageandAdditionalInfopropertiesThis PR cannot merge until
Frends.HTTP.Request/Frends.HTTP.Request/Definitions/Result.csimplements these required members for task result classes.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Frends.HTTP.Request/Frends.HTTP.Request/Request.cs` around lines 62 - 66, The Result class in Definitions/Result.cs is missing required members; add a public bool Success { get; set; } and a public ErrorInfo Error { get; set; } (where ErrorInfo is a new public class with string Message { get; set; } and string AdditionalInfo { get; set; }) to the Result class so the Request method can return the expected shape; ensure both classes are public with get/set accessors and any JSON/serialization attributes used in the project are applied consistently.
68-70:⚠️ Potential issue | 🟡 MinorUse
ArgumentExceptioninstead ofArgumentNullExceptionfor empty-string validation.Line 70 passes the custom message as the
paramNameparameter toArgumentNullException, which violates CA2208. This is an empty-string check, not a null-argument check, soArgumentExceptionis the correct exception type.Proposed fix
- if (string.IsNullOrEmpty(input.Url)) throw new ArgumentNullException("Url can not be empty."); + if (input == null) throw new ArgumentNullException(nameof(input)); + if (string.IsNullOrEmpty(input.Url)) throw new ArgumentException("Url can not be empty.", nameof(input));🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@Frends.HTTP.Request/Frends.HTTP.Request/Request.cs` around lines 68 - 70, Replace the empty-string check that throws ArgumentNullException with an ArgumentException and supply the parameter name properly; for the check in Request.cs where you validate input.Url, change the throw to something like: throw new ArgumentException("Url cannot be empty.", nameof(input.Url)) so the message is the first argument and the parameter name is passed as the second (use nameof(input.Url) or "Url" as the paramName).
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs`:
- Around line 414-435: The test
RestRequest_NonJsonErrorResponse_ShouldReturnRawStringWithStatusCode is
misleading because it hits the 200 /html endpoint; either change the test to
actually exercise a non-2xx non-JSON error response or rename it to reflect the
200 success path. Fix option A: update Input.Url to a non-2xx, non-JSON endpoint
(e.g. use an endpoint that returns 500/plain-text such as $"{BasePath}/error" or
similar) so ThrowExceptionOnErrorResponse = false is exercised and assertions
still check StatusCode and raw Body; Fix option B: if you intend to test the 200
HTML response, rename the test method to
RestRequest_HtmlResponse_ShouldReturnRawStringWithStatusCode and keep assertions
unchanged. Ensure you update the TestMethod attribute name and any references to
Input/Options accordingly.
---
Outside diff comments:
In `@Frends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.cs`:
- Around line 271-292: Add a unit test that exercises the parse-fallback branch
in Request.cs (around lines 226-230) by simulating a response whose Content-Type
suggests JSON (e.g., "application/json") but whose body is invalid JSON so
JToken.Parse throws; in the test (e.g., alongside
RestRequest_NonJsonResponse_ShouldReturnRawStringInsteadOfThrowing in
Frends.HTTP.Request.Tests/UnitTests.cs) call HTTP.Request with headers
containing application/json, a response body that is not valid JSON, and assert
that result.Body is a string (ClassicAssert.IsInstanceOf<string>), that the
string contains the original raw response content, and that result.StatusCode
equals the expected code (e.g., 200), thereby pinning the fallback behavior.
In `@Frends.HTTP.Request/Frends.HTTP.Request/Request.cs`:
- Around line 62-66: The Result class in Definitions/Result.cs is missing
required members; add a public bool Success { get; set; } and a public ErrorInfo
Error { get; set; } (where ErrorInfo is a new public class with string Message {
get; set; } and string AdditionalInfo { get; set; }) to the Result class so the
Request method can return the expected shape; ensure both classes are public
with get/set accessors and any JSON/serialization attributes used in the project
are applied consistently.
- Around line 68-70: Replace the empty-string check that throws
ArgumentNullException with an ArgumentException and supply the parameter name
properly; for the check in Request.cs where you validate input.Url, change the
throw to something like: throw new ArgumentException("Url cannot be empty.",
nameof(input.Url)) so the message is the first argument and the parameter name
is passed as the second (use nameof(input.Url) or "Url" as the paramName).
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: b32b2bd4-9dcb-4d5e-8038-91f633ecee0a
📒 Files selected for processing (4)
Frends.HTTP.Request/CHANGELOG.mdFrends.HTTP.Request/Frends.HTTP.Request.Tests/UnitTests.csFrends.HTTP.Request/Frends.HTTP.Request/Frends.HTTP.Request.csprojFrends.HTTP.Request/Frends.HTTP.Request/Request.cs
Please review my changes :)
Task Update PR template
Review Checklist
Summary by CodeRabbit
Bug Fixes
Chores