-
Notifications
You must be signed in to change notification settings - Fork 56
MCP-274 Handle HTTP Responses Better #206
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
base: master
Are you sure you want to change the base?
MCP-274 Handle HTTP Responses Better #206
Conversation
277df71 to
02d962e
Compare
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull request overview
Improve error handling for HTTP responses by extracting useful messages from JSON error bodies and making response body parsing more resilient.
Changes:
- Extend JSON error parsing to support a top-level
messagefield whenerrorsis absent. - Add a fallback in
HttpResponse.bodyAsString()to decode body bytes when text is unavailable. - Add tests covering these new behaviors.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| src/main/java/org/sonarsource/sonarqube/mcp/serverapi/ServerApiHelper.java | Parse message from JSON error bodies when errors is missing |
| src/main/java/org/sonarsource/sonarqube/mcp/http/HttpResponse.java | Fallback from getBodyText() to UTF-8 decoded getBodyBytes() |
| src/test/java/org/sonarsource/sonarqube/mcp/serverapi/ServerApiTests.java | Tests for message parsing and ignoring irrelevant JSON bodies |
| src/test/java/org/sonarsource/sonarqube/mcp/http/HttpClientProviderTests.java | Test for bodyAsString() fallback when getBodyText() is null |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var message = obj.getAsJsonPrimitive("message"); | ||
| if (message != null) { | ||
| return message.getAsString(); |
Copilot
AI
Feb 12, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
JsonObject#getAsJsonPrimitive("message") can throw if message exists but is not a JSON primitive (e.g., null, object, array). To make this robust, fetch via obj.get("message") and only read it when the element is a non-null primitive (e.g., element != null && element.isJsonPrimitive() && !element.isJsonNull()).
| var message = obj.getAsJsonPrimitive("message"); | |
| if (message != null) { | |
| return message.getAsString(); | |
| JsonElement messageElement = obj.get("message"); | |
| if (messageElement != null && messageElement.isJsonPrimitive() && !messageElement.isJsonNull()) { | |
| return messageElement.getAsJsonPrimitive().getAsString(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like a valid consideration


No description provided.