-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
Resource Access Manager - Errors unmarshalled incorrectly #2377
Comments
This might be a service model/API issue. RAM is supposed to use the |
Thanks for submitting this issue. We'll reach out to the service team to help address this issue. I think the service should be setting the |
As a short term workaround, until the service corrects the error format returned, you could temporarily swap out the SDK's error unmarshaler for this service replacing it with custom logic to extract the error code. (I'll look at adding this as a customization to the SDK as well for the RAM client) Define a custom request unmarshal error request handler function. This custom unmarshaler will be compatible with the service when the fix is made on their end. func custUnmarshalError(r *request.Request) {
defer r.HTTPResponse.Body.Close()
var jsonErr struct {
Code string `json:"code"`
Type string `json:"__type"`
Message string `json:"message"`
}
if err := json.NewDecoder(r.HTTPResponse.Body).Decode(&jsonErr); err != nil {
r.Error = awserr.NewRequestFailure(
awserr.New("SerializationError", r.HTTPResponse.Status, nil),
r.HTTPResponse.StatusCode,
r.RequestID,
)
return
}
code := r.HTTPRequest.Header.Get("X-Amzn-Errortype")
if len(code) == 0 {
code = jsonErr.Code
}
if len(code) == 0 {
code = jsonErr.Type
}
r.Error = awserr.NewRequestFailure(
awserr.New(code, jsonErr.Message, nil),
r.HTTPResponse.StatusCode,
r.RequestID,
)
} When creating the client for RAM swap the svc := ram.New(sess)
svc.Handlers.UnmarshalError.Swap(
restjson.UnmarshalErrorHandler.Name,
request.NamedHandler{
Name: "custom.unmarshalError",
Fn: custUnmarshalError,
},
) |
Updates SDK integration smoke test code generation to assert that error codes are non-empty. Related to aws#2377
Closing this issue, as ACM corrected their error response message. The SDK's integration test also validate this as well in change, 29ae2fc. |
Please fill out the sections below to help us address your issue.
Version of AWS SDK for Go?
1.16.9
Version of Go (
go version
)?go version go1.11.1 darwin/amd64
What issue did you see?
Errors from RAM do not return a value for
err.Code()
. See the following response:The RAM API returns a JSON object of:
I would expect the error object to have
.Code()
returnUnknownResourceException
, but it returns an empty stringSteps to reproduce
If you have an runnable example, please include it.
The text was updated successfully, but these errors were encountered: