Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

private/model/api: Expose RespMetadata member on errors #3217

Merged
merged 4 commits into from
Mar 24, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 10 additions & 10 deletions private/model/api/codegentest/service/restjsonservice/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions private/model/api/codegentest/service/restxmlservice/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

20 changes: 10 additions & 10 deletions private/model/api/codegentest/service/rpcservice/api.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion private/model/api/eventstream_tmpl_readertests.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ func (c *loopReader) Read(p []byte) (int, error) {
{{ define "set event type" }}
&{{ $.ShapeName }}{
{{- if $.Exception }}
respMetadata: protocol.ResponseMetadata{
RespMetadata: protocol.ResponseMetadata{
StatusCode: 200,
},
{{- end }}
Expand Down
2 changes: 1 addition & 1 deletion private/model/api/eventstream_tmpl_tests.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ func valueForType(s *Shape, visited []string) string {
w := bytes.NewBuffer(nil)
fmt.Fprintf(w, "&%s{\n", s.ShapeName)
if s.Exception {
fmt.Fprintf(w, `respMetadata: protocol.ResponseMetadata{
fmt.Fprintf(w, `RespMetadata: protocol.ResponseMetadata{
StatusCode: 200,
},
`)
Expand Down
3 changes: 2 additions & 1 deletion private/model/api/passes.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,8 @@ func exceptionCollides(name string) bool {
"String",
"GoString",
"RequestID",
"StatusCode":
"StatusCode",
"RespMetadata":
return true
}
return false
Expand Down
8 changes: 4 additions & 4 deletions private/model/api/shape.go
Original file line number Diff line number Diff line change
Expand Up @@ -691,7 +691,7 @@ type {{ $.ShapeName }} struct {

{{- if $.Exception }}
{{- $_ := $.API.AddSDKImport "private/protocol" }}
respMetadata protocol.ResponseMetadata
RespMetadata protocol.ResponseMetadata` + "`json:\"-\" xml:\"-\"`" + `
skotambkar marked this conversation as resolved.
Show resolved Hide resolved
{{- end }}

{{- if $.OutputEventStreamAPI }}
Expand Down Expand Up @@ -809,7 +809,7 @@ var exceptionShapeMethodTmpl = template.Must(
{{/* TODO allow service custom input to be used */}}
func newError{{ $.ShapeName }}(v protocol.ResponseMetadata) error {
return &{{ $.ShapeName }}{
respMetadata: v,
RespMetadata: v,
}
}

Expand Down Expand Up @@ -843,12 +843,12 @@ func (s {{ $.ShapeName }}) Error() string {

// Status code returns the HTTP status code for the request's response error.
func (s {{ $.ShapeName }}) StatusCode() int {
return s.respMetadata.StatusCode
return s.RespMetadata.StatusCode
}

// RequestID returns the service's response RequestID for request.
func (s {{ $.ShapeName }}) RequestID() string {
return s.respMetadata.RequestID
return s.RespMetadata.RequestID
}
`))

Expand Down
9 changes: 9 additions & 0 deletions private/protocol/xml/xmlutil/build.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"reflect"
"sort"
"strconv"
"strings"
"time"

"github.com/aws/aws-sdk-go/private/protocol"
Expand Down Expand Up @@ -60,6 +61,14 @@ func (b *xmlBuilder) buildValue(value reflect.Value, current *XMLNode, tag refle
return nil
}

xml := tag.Get("xml")
if len(xml) != 0 {
name := strings.SplitAfterN(xml, ",", 2)[0]
if name == "-" {
return nil
}
}

t := tag.Get("type")
if t == "" {
switch value.Kind() {
Expand Down
8 changes: 8 additions & 0 deletions private/protocol/xml/xmlutil/unmarshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,14 @@ func UnmarshalXML(v interface{}, d *xml.Decoder, wrapper string) error {
// parse deserializes any value from the XMLNode. The type tag is used to infer the type, or reflect
// will be used to determine the type from r.
func parse(r reflect.Value, node *XMLNode, tag reflect.StructTag) error {
xml := tag.Get("xml")
if len(xml) != 0 {
name := strings.SplitAfterN(xml, ",", 2)[0]
if name == "-" {
return nil
}
}

rtype := r.Type()
if rtype.Kind() == reflect.Ptr {
rtype = rtype.Elem() // check kind of actual element type
Expand Down
Loading