func retry50x[T any]()

in internal/cloudsql/retry.go [59:93]


func retry50x[T any](
	ctx context.Context,
	f func(context.Context) (*T, error),
	waitDuration func(int) time.Duration,
) (*T, error) {
	const maxRetries = 5
	var (
		resp *T
		err  error
	)
	for i := 0; i < maxRetries; i++ {
		resp, err = f(ctx)
		// If err is nil, break and return the response.
		if err == nil {
			break
		}

		gErr, ok := err.(*googleapi.Error)
		// If err is not a googleapi.Error, don't retry.
		if !ok {
			return nil, err
		}
		// If the error code is not a 50x error, don't retry.
		if gErr.Code < 500 {
			return nil, err
		}

		if wErr := wait(ctx, waitDuration(i)); wErr != nil {
			err = wErr
			break
		}

	}
	return resp, err
}