您可以参考本文档中提供的常见问题排查SDK使用中的问题。
错误码 | 错误信息 | 原因 | 解决方法 |
---|---|---|---|
SDK.CanNotResolveEndpoint |
Can not resolve endpoint, please check the user guide |
SDK无法自动获取调用的产品在特定region的endpoint(域名)。 | 检查提供的地域ID和endpoint是否正确。获取endpoint后,可以通过以下代码设定endpoint:
|
SDK.JsonUnmarshalError |
Failed to unmarshal response, but you can get the data via response.GetHttpStatusCode() and response.GetHttpContentString() |
SDK反序列化应答失败,大多情况下是由于SDK实际收到的应答结构与ApiMeta不符,例如字段不匹配,格式不正确等原因导致的。 | 应答解析 |
SDK.TimeoutError |
The request timed out 4 times(3 for retry), perhaps we should have the threshold raised a little? |
请求超时,并且所有重试均失败。 |
|
SDK.AsyncFunctionNotEnabled |
Async function is not enabled in client, please invoke ‘client.EnableAsync()’ function |
在未开启异步请求开关的情况下,调用了异步接口。 | 开启异步功能即可,详情参见异步调用。 |
应答解析
在SDK反序列化失败时,您可以忽略,通过提取response类中的原始HTTP应答,依然可以获取应答中的信息。
说明 阿里云Go SDK依赖了jmespath,因此当应答内容为JSON时,您可以直接使用jmespath来解析应答。
response, err := client.CreateInstance(request)
if err != nil {
// 异常处理
if clientErr, isClientErr := err.(*errors.ClientError); isClientErr {
if clientErr.ErrorCode() == errors.JsonUnmarshalErrorCode {
// 您可以直接通过我们的封装方法来分别获取原始应答中的数据
// 应答中的http状态码,类型:int
statusCode := response.GetHttpStatus()
// 应答中的http头,类型:map[string][]string
responseHeader := response.GetHttpHeaders()
// 应答中的body内容,类型:[]byte
responseBytes := response.GetHttpContentBytes()
// 应答中的body内容,类型:string, 等价于`string(response.GetHttpContentBytes())`
responseContent := response.GetHttpContentString()
// 您也可以直接获取原始应答,类型:net/http.Response
httpResponse := response.GetOriginHttpResponse()
}
}
}
在文档使用中是否遇到以下问题
更多建议
匿名提交