mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-08 22:30:41 +00:00
Update Go AWS SDK to the latest version
This commit is contained in:
committed by
Andrey Smirnov
parent
d08be990ef
commit
94a72b23ff
+1242
-364
File diff suppressed because it is too large
Load Diff
+11
-15
@@ -6,12 +6,11 @@ package restjson
|
||||
//go:generate go run -tags codegen ../../../models/protocol_tests/generate.go ../../../models/protocol_tests/output/rest-json.json unmarshal_test.go
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/json/jsonutil"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/jsonrpc"
|
||||
"github.com/aws/aws-sdk-go/private/protocol/rest"
|
||||
)
|
||||
@@ -33,6 +32,9 @@ func Build(r *request.Request) {
|
||||
rest.Build(r)
|
||||
|
||||
if t := rest.PayloadType(r.Params); t == "structure" || t == "" {
|
||||
if v := r.HTTPRequest.Header.Get("Content-Type"); len(v) == 0 {
|
||||
r.HTTPRequest.Header.Set("Content-Type", "application/json")
|
||||
}
|
||||
jsonrpc.Build(r)
|
||||
}
|
||||
}
|
||||
@@ -54,26 +56,20 @@ func UnmarshalMeta(r *request.Request) {
|
||||
// UnmarshalError unmarshals a response error for the REST JSON protocol.
|
||||
func UnmarshalError(r *request.Request) {
|
||||
defer r.HTTPResponse.Body.Close()
|
||||
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
|
||||
bodyBytes, err := ioutil.ReadAll(r.HTTPResponse.Body)
|
||||
|
||||
var jsonErr jsonErrorResponse
|
||||
err := jsonutil.UnmarshalJSONError(&jsonErr, r.HTTPResponse.Body)
|
||||
if err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed reading REST JSON error response", err)
|
||||
return
|
||||
}
|
||||
if len(bodyBytes) == 0 {
|
||||
r.Error = awserr.NewRequestFailure(
|
||||
awserr.New("SerializationError", r.HTTPResponse.Status, nil),
|
||||
awserr.New(request.ErrCodeSerialization,
|
||||
"failed to unmarshal response error", err),
|
||||
r.HTTPResponse.StatusCode,
|
||||
"",
|
||||
r.RequestID,
|
||||
)
|
||||
return
|
||||
}
|
||||
var jsonErr jsonErrorResponse
|
||||
if err := json.Unmarshal(bodyBytes, &jsonErr); err != nil {
|
||||
r.Error = awserr.New("SerializationError", "failed decoding REST JSON error response", err)
|
||||
return
|
||||
}
|
||||
|
||||
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
|
||||
if code == "" {
|
||||
code = jsonErr.Code
|
||||
}
|
||||
|
||||
Generated
Vendored
+79
@@ -0,0 +1,79 @@
|
||||
// +build go1.8
|
||||
|
||||
package restjson
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"encoding/hex"
|
||||
"io/ioutil"
|
||||
"net/http"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/request"
|
||||
)
|
||||
|
||||
func TestUnmarshalError_SerializationError(t *testing.T) {
|
||||
cases := map[string]struct {
|
||||
Request *request.Request
|
||||
ExpectMsg string
|
||||
ExpectBytes []byte
|
||||
}{
|
||||
"empty body": {
|
||||
Request: &request.Request{
|
||||
Data: &struct{}{},
|
||||
HTTPResponse: &http.Response{
|
||||
StatusCode: 400,
|
||||
Header: http.Header{
|
||||
"X-Amzn-Requestid": []string{"abc123"},
|
||||
},
|
||||
Body: ioutil.NopCloser(
|
||||
bytes.NewReader([]byte{}),
|
||||
),
|
||||
},
|
||||
},
|
||||
ExpectMsg: "error message missing",
|
||||
},
|
||||
"HTML body": {
|
||||
Request: &request.Request{
|
||||
Data: &struct{}{},
|
||||
HTTPResponse: &http.Response{
|
||||
StatusCode: 400,
|
||||
Header: http.Header{
|
||||
"X-Amzn-Requestid": []string{"abc123"},
|
||||
},
|
||||
Body: ioutil.NopCloser(
|
||||
bytes.NewReader([]byte(`<html></html>`)),
|
||||
),
|
||||
},
|
||||
},
|
||||
ExpectBytes: []byte(`<html></html>`),
|
||||
ExpectMsg: "failed decoding",
|
||||
},
|
||||
}
|
||||
|
||||
for name, c := range cases {
|
||||
t.Run(name, func(t *testing.T) {
|
||||
req := c.Request
|
||||
|
||||
UnmarshalError(req)
|
||||
if req.Error == nil {
|
||||
t.Fatal("expect error, got none")
|
||||
}
|
||||
|
||||
aerr := req.Error.(awserr.RequestFailure)
|
||||
if e, a := request.ErrCodeSerialization, aerr.Code(); e != a {
|
||||
t.Errorf("expect %v, got %v", e, a)
|
||||
}
|
||||
|
||||
uerr := aerr.OrigErr().(awserr.UnmarshalError)
|
||||
if e, a := c.ExpectMsg, uerr.Message(); !strings.Contains(a, e) {
|
||||
t.Errorf("Expect %q, in %q", e, a)
|
||||
}
|
||||
if e, a := c.ExpectBytes, uerr.Bytes(); !bytes.Equal(e, a) {
|
||||
t.Errorf("expect:\n%v\nactual:\n%v", hex.Dump(e), hex.Dump(a))
|
||||
}
|
||||
})
|
||||
}
|
||||
}
|
||||
+549
-347
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user