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

Add error handling function to match error codes in nested API errors #59

Open
gdavison opened this issue Jul 8, 2021 · 0 comments
Open
Labels
enhancement New feature or request

Comments

@gdavison
Copy link
Contributor

gdavison commented Jul 8, 2021

Description

Some AWS API errors return a fairly generic error code with a nested specific code. Currently we only check the top-level error code, and sometimes check the error message. AWS strongly discourages checking the error message, since it can change.

Using the current functions, this is how a specific error message can be checked for

if tfawserr.ErrCodeEquals(err, storagegateway.ErrCodeInvalidGatewayRequestException) {
	var awsErr awserr.Error
	if errors.As(err, &awsErr) {
		nestedErr := awsErr.OrigErr()
		if nestedErr != nil && tfawserr.ErrCodeEquals(nestedErr, "FileSystemAssociationNotFound") {
			return nil, FsxFileSystemStatusNotFound, nil
		}
	}
}

Potential Library Implementation

func ErrCodeEqualsNested(err error, code string) (awserr.Error, bool)

The function should loop until the error code matches or err.OrigErr() returns nil. The awserr.Error return value will be the matched error or nil. The bool return value will be true if there is a match.

References

hashicorp/terraform-provider-aws#20082 (comment)

@gdavison gdavison added the enhancement New feature or request label Jul 8, 2021
@gdavison gdavison added this to the v1.0.0 milestone Jul 8, 2021
@gdavison gdavison removed this from the v1.0.0 milestone Sep 25, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant