Skip to content

Commit

Permalink
feedback around test and doc.go
Browse files Browse the repository at this point in the history
  • Loading branch information
skotambkar committed Oct 5, 2020
1 parent 88d60f1 commit bcd343e
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 48 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ func TestCustomErrorDeserialization(t *testing.T) {
expectedError: "InvalidChangeBatch: ChangeBatch errors occurred",
expectedRequestID: "b25f48e8-84fd-11e6-80d9-574e0c4664cb",
},

"standardRestXMLError": {
responseStatus: 500,
responseBody: []byte(`<?xml version="1.0"?>
Expand All @@ -48,6 +49,7 @@ func TestCustomErrorDeserialization(t *testing.T) {
expectedError: "1 validation error detected:",
expectedRequestID: "b25f48e8-84fd-11e6-80d9-574e0c4664cb",
},

"Success response": {
responseStatus: 200,
responseBody: []byte(`<?xml version="1.0" encoding="UTF-8"?>
Expand Down Expand Up @@ -97,12 +99,15 @@ func TestCustomErrorDeserialization(t *testing.T) {
t.Fatalf("expected error to be %s, got %s", e, a)
}

var awsResponseError responseError
if !errors.As(err, &awsResponseError) {
t.Fatalf("expected error to be of type %T, was not", awsResponseError)
var responseError interface {
ServiceRequestID() string
}

if !errors.As(err, &responseError) {
t.Fatalf("expected error to be of type %T, was not", responseError)
}

if e, a := c.expectedRequestID, awsResponseError.ServiceRequestID(); !strings.EqualFold(e, a) {
if e, a := c.expectedRequestID, responseError.ServiceRequestID(); !strings.EqualFold(e, a) {
t.Fatalf("expected request id to be %s, got %s", e, a)
}
}
Expand All @@ -116,7 +121,3 @@ func TestCustomErrorDeserialization(t *testing.T) {
})
}
}

type responseError interface {
ServiceRequestID() string
}
78 changes: 38 additions & 40 deletions service/route53/internal/customizations/doc.go
Original file line number Diff line number Diff line change
@@ -1,41 +1,39 @@
/*
Package customizations provides customizations for the Amazon Route53 API client.
This package provides support for following customizations
Process Response Middleware: used for custom error deserializing
Process Response Middleware
Route53 operation: ChangeResourceRecordSets can have an error response returned in
a slightly different format. This customization is only applicable to
ChangeResourceRecordSets operation of Route53.
Here's a sample error response:
<?xml version="1.0" encoding="UTF-8"?>
<InvalidChangeBatch xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
<Messages>
<Message>Tried to create resource record set duplicate.example.com. type A, but it already exists</Message>
</Messages>
</InvalidChangeBatch>
The processResponse middleware customizations enables SDK to check for an error
response starting with `InvalidChangeBatch` tag prior to deserialization.
As this check in error response needs to be performed earlier than response
deserialization. Since the behavior of Deserialization is in
reverse order to the other stack steps its easier to consider that "after" means
"before".
Middleware layering:
HTTP Response -> process response error -> deserialize
In case the returned error response has `InvalidChangeBatch` format, the error is
deserialized and returned. The operation deserializer does not attempt to deserialize
as an error is returned by the process response error middleware.
*/
// Package customizations provides customizations for the Amazon Route53 API client.
//
// This package provides support for following customizations
// Process Response Middleware: used for custom error deserializing
//
//
// Process Response Middleware
//
// Route53 operation "ChangeResourceRecordSets" can have an error response returned in
// a slightly different format. This customization is only applicable to
// ChangeResourceRecordSets operation of Route53.
//
// Here's a sample error response:
// <?xml version="1.0" encoding="UTF-8"?>
// <InvalidChangeBatch xmlns="https://route53.amazonaws.com/doc/2013-04-01/">
// <Messages>
// <Message>Tried to create resource record set duplicate.example.com. type A, but it already exists</Message>
// </Messages>
// </InvalidChangeBatch>
//
//
// The processResponse middleware customizations enables SDK to check for an error
// response starting with `InvalidChangeBatch` tag prior to deserialization.
//
// As this check in error response needs to be performed earlier than response
// deserialization. Since the behavior of Deserialization is in
// reverse order to the other stack steps its easier to consider that "after" means
// "before".
//
// Middleware layering:
//
// HTTP Response -> process response error -> deserialize
//
//
// In case the returned error response has `InvalidChangeBatch` format, the error is
// deserialized and returned. The operation deserializer does not attempt to deserialize
// as an error is returned by the process response error middleware.
//
package customizations

0 comments on commit bcd343e

Please sign in to comment.