3 Star 1 Fork 0

Gitee 极速下载/aws-sdk-go

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
此仓库是为了提升国内下载速度的镜像仓库,每日同步一次。 原始仓库: https://github.com/aws/aws-sdk-go
克隆/下载
unmarshall_error.go 1.46 KB
一键复制 编辑 原始数据 按行查看 历史
package simpledb
import (
"encoding/xml"
"io"
"io/ioutil"
"strings"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
)
type xmlErrorDetail struct {
Code string `xml:"Code"`
Message string `xml:"Message"`
}
type xmlErrorResponse struct {
XMLName xml.Name `xml:"Response"`
Errors []xmlErrorDetail `xml:"Errors>Error"`
RequestID string `xml:"RequestID"`
}
func unmarshalError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
defer io.Copy(ioutil.Discard, r.HTTPResponse.Body)
if r.HTTPResponse.ContentLength == int64(0) {
// No body, use status code to generate an awserr.Error
r.Error = awserr.NewRequestFailure(
awserr.New(strings.Replace(r.HTTPResponse.Status, " ", "", -1), r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
"",
)
return
}
resp := &xmlErrorResponse{}
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
if err != nil && err != io.EOF {
r.Error = awserr.New("SerializationError", "failed to decode SimpleDB XML error response", nil)
} else if len(resp.Errors) == 0 {
r.Error = awserr.New("MissingError", "missing error code in SimpleDB XML error response", nil)
} else {
// If there are multiple error codes, return only the first as the aws.Error interface only supports
// one error code.
r.Error = awserr.NewRequestFailure(
awserr.New(resp.Errors[0].Code, resp.Errors[0].Message, nil),
r.HTTPResponse.StatusCode,
resp.RequestID,
)
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/mirrors/aws-sdk-go.git
git@gitee.com:mirrors/aws-sdk-go.git
mirrors
aws-sdk-go
aws-sdk-go
v1.14.28

搜索帮助