Skip to content

Commit

Permalink
Add 'tfresource.RetryWhenHTTPStatusCodeEquals'.
Browse files Browse the repository at this point in the history
  • Loading branch information
ewbankkit committed Oct 24, 2023
1 parent 1154b39 commit 157f728
Showing 1 changed file with 12 additions and 1 deletion.
13 changes: 12 additions & 1 deletion internal/tfresource/retry.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func RetryWhen(ctx context.Context, timeout time.Duration, f func() (interface{}
return output, nil
}

// RetryWhenAWSErrCodeEquals retries the specified function when it returns one of the specified AWS error code.
// RetryWhenAWSErrCodeEquals retries the specified function when it returns one of the specified AWS error codes.
func RetryWhenAWSErrCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), codes ...string) (interface{}, error) { // nosemgrep:ci.aws-in-func-name
return RetryWhen(ctx, timeout, f, func(err error) (bool, error) {
if tfawserr.ErrCodeEquals(err, codes...) || tfawserr_sdkv2.ErrCodeEquals(err, codes...) {
Expand Down Expand Up @@ -135,6 +135,17 @@ func RetryUntilEqual[T comparable](ctx context.Context, timeout time.Duration, t
return output, nil
}

// RetryWhenHTTPStatusCodeEquals retries the specified function when it returns one of the specified HTTP status codes.
func RetryWhenHTTPStatusCodeEquals(ctx context.Context, timeout time.Duration, f func() (interface{}, error), statusCodes ...int) (interface{}, error) { // nosemgrep:ci.aws-in-func-name
return RetryWhen(ctx, timeout, f, func(err error) (bool, error) {
if tfawserr_sdkv2.ErrHTTPStatusCodeEquals(err, statusCodes...) {
return true, err
}

return false, err
})
}

var ErrFoundResource = errors.New(`found resource`)

// RetryUntilNotFound retries the specified function until it returns a retry.NotFoundError.
Expand Down

0 comments on commit 157f728

Please sign in to comment.