Skip to content

混元SDK怎么处理异常捕获? #289

@unfish

Description

@unfish

代码:
public async IAsyncEnumerable<(ResultType resultType, string result)> SendMessageStream(ApiChatInput input)
{
Credential cred = new Credential {
SecretId = SecretId,
SecretKey = SecretKey
};
HunyuanClient _client = new HunyuanClient(cred, "ap-guangzhou");
var req = new ChatProRequest()
{
Messages = GetMsgBody(input)
};
var resp = await _client.ChatPro(req);
foreach (var sse in resp)
{
var o = JObject.Parse(sse.Data);
yield return (ResultType.Answer, o["Choices"][0]["Delta"]["Content"].Value());
}
}
在IAsyncEnumerable类型的方法内部不允许使用try catch,但如果这个请求过程中出现参数错误之类的它又会直接抛出异常,我如何获取到请求异常后的Message呢?比如地域不支持,或者余额不足之类的。

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions