Skip to content

Add JSON parsing to Response class initialization#52

Open
HernandoR wants to merge 2 commits intovolcengine:masterfrom
HernandoR:patch-1
Open

Add JSON parsing to Response class initialization#52
HernandoR wants to merge 2 commits intovolcengine:masterfrom
HernandoR:patch-1

Conversation

@HernandoR
Copy link

No description provided.

Copilot AI review requested due to automatic review settings March 20, 2026 07:12
Copy link

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

This PR updates the SDK core Response wrapper to eagerly parse the underlying HTTP response body as JSON during initialization, extracting Result and ResponseMetadata.

Changes:

  • Add JSON parsing when constructing Response.
  • Populate Response.result and Response.metadata directly from parsed payload.

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

@@ -1,5 +1,12 @@
import json
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

PEP8: add a blank line after the import and before the class definition (top-level class definitions should be separated by two blank lines).

Suggested change
import json
import json

Copilot uses AI. Check for mistakes.
Comment on lines +11 to +12
self.result = data.get("Result")
self.metadata = data.get("ResponseMetadata")
Copy link

Copilot AI Mar 20, 2026

Choose a reason for hiding this comment

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

ResponseMetadata error handling is skipped here: if the JSON contains a ResponseMetadata.Error block, Response will still populate result/metadata and no ApiException is raised. To keep behavior consistent with DeserializedResponseInterceptor.deserialize (which raises on Error / missing ResponseMetadata), consider checking ResponseMetadata.Error and raising the same ApiException (or deferring JSON parsing to that interceptor).

Suggested change
self.result = data.get("Result")
self.metadata = data.get("ResponseMetadata")
metadata = data.get("ResponseMetadata")
if metadata is None:
raise ValueError("Missing ResponseMetadata in HTTP response.")
error = metadata.get("Error") if isinstance(metadata, dict) else None
if error:
raise ValueError(f"API returned error in ResponseMetadata: {error}")
self.metadata = metadata
self.result = data.get("Result")

Copilot uses AI. Check for mistakes.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
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