mirror of
https://github.com/thegeeklab/drone-s3-sync.git
synced 2024-07-06 06:20:50 +02:00
38 lines
906 B
Go
38 lines
906 B
Go
|
package query
|
||
|
|
||
|
import (
|
||
|
"encoding/xml"
|
||
|
"io"
|
||
|
|
||
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
||
|
"github.com/aws/aws-sdk-go/aws/request"
|
||
|
)
|
||
|
|
||
|
type xmlErrorResponse struct {
|
||
|
XMLName xml.Name `xml:"ErrorResponse"`
|
||
|
Code string `xml:"Error>Code"`
|
||
|
Message string `xml:"Error>Message"`
|
||
|
RequestID string `xml:"RequestId"`
|
||
|
}
|
||
|
|
||
|
// UnmarshalError unmarshals an error response for an AWS Query service.
|
||
|
func UnmarshalError(r *request.Request) {
|
||
|
defer r.HTTPResponse.Body.Close()
|
||
|
|
||
|
resp := &xmlErrorResponse{}
|
||
|
err := xml.NewDecoder(r.HTTPResponse.Body).Decode(resp)
|
||
|
if err != nil && err != io.EOF {
|
||
|
r.Error = awserr.New("SerializationError", "failed to decode query XML error response", err)
|
||
|
} else {
|
||
|
reqID := resp.RequestID
|
||
|
if reqID == "" {
|
||
|
reqID = r.RequestID
|
||
|
}
|
||
|
r.Error = awserr.NewRequestFailure(
|
||
|
awserr.New(resp.Code, resp.Message, nil),
|
||
|
r.HTTPResponse.StatusCode,
|
||
|
reqID,
|
||
|
)
|
||
|
}
|
||
|
}
|