Skip to content

Commit 3feee2a

Browse files
committed
PR feedback updates
1 parent 7537c16 commit 3feee2a

File tree

5 files changed

+78
-19
lines changed

5 files changed

+78
-19
lines changed

private/model/api/api.go

+21-14
Original file line numberDiff line numberDiff line change
@@ -607,6 +607,7 @@ func newClient(cfg aws.Config, handlers request.Handlers, partitionID, endpoint,
607607
svc.Handlers.Build.PushBackNamed({{ .ProtocolPackage }}.BuildHandler)
608608
svc.Handlers.Unmarshal.PushBackNamed({{ .ProtocolPackage }}.UnmarshalHandler)
609609
svc.Handlers.UnmarshalMeta.PushBackNamed({{ .ProtocolPackage }}.UnmarshalMetaHandler)
610+
610611
{{- if and $.WithGeneratedTypedErrors (gt (len $.ShapeListErrors) 0) }}
611612
{{- $_ := $.AddSDKImport "private/protocol" }}
612613
svc.Handlers.UnmarshalError.PushBackNamed(
@@ -615,16 +616,20 @@ func newClient(cfg aws.Config, handlers request.Handlers, partitionID, endpoint,
615616
{{- else }}
616617
svc.Handlers.UnmarshalError.PushBackNamed({{ .ProtocolPackage }}.UnmarshalErrorHandler)
617618
{{- end }}
618-
{{ if .HasEventStream }}
619-
svc.Handlers.BuildStream.PushBackNamed({{ .ProtocolPackage }}.BuildHandler)
620-
svc.Handlers.UnmarshalStream.PushBackNamed({{ .ProtocolPackage }}.UnmarshalHandler)
621-
{{ end }}
622619
623-
{{ if .UseInitMethods }}// Run custom client initialization if present
624-
if initClient != nil {
625-
initClient(svc.Client)
626-
}
627-
{{ end }}
620+
{{- if .HasEventStream }}
621+
622+
svc.Handlers.BuildStream.PushBackNamed({{ .ProtocolPackage }}.BuildHandler)
623+
svc.Handlers.UnmarshalStream.PushBackNamed({{ .ProtocolPackage }}.UnmarshalHandler)
624+
{{- end }}
625+
626+
{{- if .UseInitMethods }}
627+
628+
// Run custom client initialization if present
629+
if initClient != nil {
630+
initClient(svc.Client)
631+
}
632+
{{- end }}
628633
629634
return svc
630635
}
@@ -634,11 +639,13 @@ func newClient(cfg aws.Config, handlers request.Handlers, partitionID, endpoint,
634639
func (c *{{ .StructName }}) newRequest(op *request.Operation, params, data interface{}) *request.Request {
635640
req := c.NewRequest(op, params, data)
636641
637-
{{ if .UseInitMethods }}// Run custom request initialization if present
638-
if initRequest != nil {
639-
initRequest(req)
640-
}
641-
{{ end }}
642+
{{- if .UseInitMethods }}
643+
644+
// Run custom request initialization if present
645+
if initRequest != nil {
646+
initRequest(req)
647+
}
648+
{{- end }}
642649
643650
return req
644651
}

private/model/api/load.go

+4
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,11 @@ func (a *API) Setup() error {
221221

222222
a.findEndpointDiscoveryOp()
223223
a.injectUnboundedOutputStreaming()
224+
225+
// Enables generated types for APIs using REST-JSON and JSONRPC protocols.
226+
// Other protocols will be added as supported.
224227
a.enableGeneratedTypedErrors()
228+
225229
if err := a.customizationPasses(); err != nil {
226230
return err
227231
}

private/protocol/restjson/unmarshal_error.go

+9-4
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,11 @@ import (
1414
"github.com/aws/aws-sdk-go/private/protocol/rest"
1515
)
1616

17+
const (
18+
errorTypeHeader = "X-Amzn-Errortype"
19+
errorMessageHeader = "X-Amzn-Errormessage"
20+
)
21+
1722
// UnmarshalTypedError provides unmarshaling errors API response errors
1823
// for both typed and untyped errors.
1924
type UnmarshalTypedError struct {
@@ -36,8 +41,8 @@ func (u *UnmarshalTypedError) UnmarshalError(
3641
respMeta protocol.ResponseMetadata,
3742
) (error, error) {
3843

39-
code := resp.Header.Get("X-Amzn-Errortype")
40-
msg := resp.Header.Get("X-Amzn-Errormessage")
44+
code := resp.Header.Get(errorTypeHeader)
45+
msg := resp.Header.Get(errorMessageHeader)
4146

4247
body := resp.Body
4348
if len(code) == 0 {
@@ -106,11 +111,11 @@ func UnmarshalError(r *request.Request) {
106111
return
107112
}
108113

109-
code := r.HTTPResponse.Header.Get("X-Amzn-Errortype")
114+
code := r.HTTPResponse.Header.Get(errorTypeHeader)
110115
if code == "" {
111116
code = jsonErr.Code
112117
}
113-
msg := r.HTTPResponse.Header.Get("X-Amzn-Errormessage")
118+
msg := r.HTTPResponse.Header.Get(errorMessageHeader)
114119
if msg == "" {
115120
msg = jsonErr.Message
116121
}

private/protocol/restjson/unmarshal_error_test.go

+40
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import (
1919

2020
const unknownErrJSON = `{"code":"UnknownError", "message":"error message", "something":123}`
2121
const simpleErrJSON = `{"code":"SimpleError", "message":"some message", "foo":123}`
22+
const simpleNoCodeJSON = `{"message":"some message", "foo":123}`
2223

2324
type SimpleError struct {
2425
_ struct{} `type:"structure"`
@@ -145,6 +146,45 @@ func TestUnmarshalTypedError(t *testing.T) {
145146
},
146147
Err: "failed decoding",
147148
},
149+
"unknown from header": {
150+
Response: &http.Response{
151+
Header: http.Header{
152+
errorTypeHeader: []string{"UnknownError"},
153+
errorMessageHeader: []string{"error message"},
154+
},
155+
Body: ioutil.NopCloser(nil),
156+
},
157+
Expect: awserr.NewRequestFailure(
158+
awserr.New("UnknownError", "error message", nil),
159+
respMeta.StatusCode,
160+
respMeta.RequestID,
161+
),
162+
},
163+
"code from header": {
164+
Response: &http.Response{
165+
Header: http.Header{
166+
errorTypeHeader: []string{"SimpleError"},
167+
},
168+
Body: ioutil.NopCloser(strings.NewReader(simpleNoCodeJSON)),
169+
},
170+
Expect: &SimpleError{
171+
Message2: aws.String("some message"),
172+
Foo: aws.Int64(123),
173+
},
174+
},
175+
"ignore message header": {
176+
Response: &http.Response{
177+
Header: http.Header{
178+
errorTypeHeader: []string{"SimpleError"},
179+
errorMessageHeader: []string{"error message"},
180+
},
181+
Body: ioutil.NopCloser(strings.NewReader(simpleNoCodeJSON)),
182+
},
183+
Expect: &SimpleError{
184+
Message2: aws.String("some message"),
185+
Foo: aws.Int64(123),
186+
},
187+
},
148188
}
149189

150190
for name, c := range cases {

private/protocol/unmarshal_error.go

+4-1
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,14 @@ func NewUnmarshalErrorHandler(unmarshaler ErrorUnmarshaler) *UnmarshalErrorHandl
2727
}
2828
}
2929

30+
// UnmarshalErrorHandlerName is the name of the named handler.
31+
const UnmarshalErrorHandlerName = "awssdk.protocol.UnmarshalError"
32+
3033
// NamedHandler returns a NamedHandler for the unmarshaler using the set of
3134
// errors the unmarshaler was initialized for.
3235
func (u *UnmarshalErrorHandler) NamedHandler() request.NamedHandler {
3336
return request.NamedHandler{
34-
Name: "awssdk.protocol.UnmarshalError",
37+
Name: UnmarshalErrorHandlerName,
3538
Fn: u.UnmarshalError,
3639
}
3740
}

0 commit comments

Comments
 (0)