Skip to content

dev/issues-4#247

Open
luk384090-cloud wants to merge 5 commits into
mainfrom
dev/issues-4
Open

dev/issues-4#247
luk384090-cloud wants to merge 5 commits into
mainfrom
dev/issues-4

Conversation

@luk384090-cloud

Copy link
Copy Markdown
Collaborator

No description provided.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Caution

The consumer version of Gemini Code Assist on GitHub has been sunset. All code review activity has officially ceased.

Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java Outdated
Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java Outdated
Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java Outdated
Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java Outdated
Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java Outdated
Comment thread src/main/java/com/alibaba/dashscope/common/DashScopeResult.java
zhansheng.lzs added 3 commits July 24, 2026 10:53
…rmed/empty responses

- Add null/empty message checks and try-catch for all JsonUtils.parse call sites
  (WebSocket, HTTP, isFlattenResult, encrypted branches) using PublicErrorDef.INTERNAL_ERROR
- Introduce PublicErrorDef (copied from com.alibaba.dashscope:error:1.0.0) for
  standardized error codes and messages
…sponse redundancy

Extracted setInternalError(), parseJson(), populateFromHttpJson(), and fromWebSocketMessage()
to eliminate repeated error-handling and JSON field extraction across three fromResponse() overloads.
: payload.get(ApiKeywords.USAGE));
}
}
fromWebSocketMessage(response.getMessage());

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

response.getMessage() 需要做下防御

}
this.output = jsonObject;
}
populateFromHttpJson(jsonObject);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

jsonObject.has(ApiKeywords.OUTPUT) 和 jsonObject.has(ApiKeywords.DATA) 都对this.output赋值?

}

private void populateFromHttpJson(JsonObject jsonObject) {
if (jsonObject.has(ApiKeywords.OUTPUT)) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

拿到外面。

: "");
if (jsonObject.has(ApiKeywords.DATA)) {
jsonObject.remove(ApiKeywords.REQUEST_ID);
this.output = jsonObject;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

拿到外面。

}
JsonObject jsonObject =
parseJson(encryptedMessage, "Failed to parse encrypted HTTP response message");
if (jsonObject == null) return (T) this;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

加{}

jsonObject.remove(ApiKeywords.REQUEST_ID);
}
this.output = parseJson(plainOutput, "Failed to parse decrypted output");
if (this.output == null) return (T) this;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

应该是:
} else {
this.output = null;
}

this.output = parseJson(plainOutput, "Failed to parse decrypted output");
if (this.output == null) return (T) this;
}
populateFromHttpJson(jsonObject);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

将2个output 移出函数。

if (jsonObject.has(ApiKeywords.OUTPUT)) {
  this.output =
      jsonObject.get(ApiKeywords.OUTPUT).isJsonNull()
          ? null
          : jsonObject.get(ApiKeywords.OUTPUT).getAsJsonObject();
}

populateFromHttpJson(jsonObject);

if (jsonObject.has(ApiKeywords.DATA)) {
  this.output = jsonObject;
}

? jsonObject.get(ApiKeywords.MESSAGE).getAsString()
: "");
if (jsonObject.has(ApiKeywords.DATA)) {
jsonObject.remove(ApiKeywords.REQUEST_ID);

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

这句话保留。

return (T) this;
}
JsonObject jsonObject = parseJson(message, "Failed to parse HTTP response as JSON: {}");
if (jsonObject == null) return (T) this;

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

加{}

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