forked from aws/aws-sdk-go
-
Notifications
You must be signed in to change notification settings - Fork 1
/
unmarshal_error.go
77 lines (60 loc) · 1.9 KB
/
unmarshal_error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package route53
import (
"bytes"
"encoding/xml"
"io/ioutil"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/aws/request"
"github.com/aws/aws-sdk-go/private/protocol/restxml"
)
type baseXMLErrorResponse struct {
XMLName xml.Name
}
type standardXMLErrorResponse struct {
XMLName xml.Name `xml:"ErrorResponse"`
Code string `xml:"Error>Code"`
Message string `xml:"Error>Message"`
RequestID string `xml:"RequestId"`
}
type invalidChangeBatchXMLErrorResponse struct {
XMLName xml.Name `xml:"InvalidChangeBatch"`
Messages []string `xml:"Messages>Message"`
}
func unmarshalChangeResourceRecordSetsError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
responseBody, err := ioutil.ReadAll(r.HTTPResponse.Body)
if err != nil {
r.Error = awserr.New("SerializationError", "failed to read Route53 XML error response", err)
return
}
baseError := &baseXMLErrorResponse{}
if err := xml.Unmarshal(responseBody, baseError); err != nil {
r.Error = awserr.New("SerializationError", "failed to decode Route53 XML error response", err)
return
}
switch baseError.XMLName.Local {
case "InvalidChangeBatch":
unmarshalInvalidChangeBatchError(r, responseBody)
default:
r.HTTPResponse.Body = ioutil.NopCloser(bytes.NewReader(responseBody))
restxml.UnmarshalError(r)
}
}
func unmarshalInvalidChangeBatchError(r *request.Request, requestBody []byte) {
resp := &invalidChangeBatchXMLErrorResponse{}
err := xml.Unmarshal(requestBody, resp)
if err != nil {
r.Error = awserr.New("SerializationError", "failed to decode query XML error response", err)
return
}
const errorCode = "InvalidChangeBatch"
errors := []error{}
for _, msg := range resp.Messages {
errors = append(errors, awserr.New(errorCode, msg, nil))
}
r.Error = awserr.NewRequestFailure(
awserr.NewBatchError(errorCode, "ChangeBatch errors occured", errors),
r.HTTPResponse.StatusCode,
r.RequestID,
)
}