remote: Convert to RecoverableError using errors.As (#12103)

In storage/remote, try converting to RecoverableError using errors.As,
instead of through direct casting.

Signed-off-by: Arve Knudsen <arve.knudsen@gmail.com>
This commit is contained in:
Arve Knudsen 2023-03-08 21:58:09 +01:00 committed by GitHub
parent 9afbb23d4a
commit 435b500de7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 6 deletions

View file

@ -109,10 +109,11 @@ func TestClientRetryAfter(t *testing.T) {
RetryOnRateLimit: false,
}
var recErr RecoverableError
c := getClient(conf)
err = c.Store(context.Background(), []byte{})
_, ok := err.(RecoverableError)
require.False(t, ok, "Recoverable error not expected.")
require.False(t, errors.As(err, &recErr), "Recoverable error not expected.")
conf = &ClientConfig{
URL: &config_util.URL{URL: serverURL},
@ -122,8 +123,7 @@ func TestClientRetryAfter(t *testing.T) {
c = getClient(conf)
err = c.Store(context.Background(), []byte{})
_, ok = err.(RecoverableError)
require.True(t, ok, "Recoverable error was expected.")
require.True(t, errors.As(err, &recErr), "Recoverable error was expected.")
}
func TestRetryAfterDuration(t *testing.T) {

View file

@ -1569,8 +1569,8 @@ func sendWriteRequestWithBackoff(ctx context.Context, cfg config.QueueConfig, l
}
// If the error is unrecoverable, we should not retry.
backoffErr, ok := err.(RecoverableError)
if !ok {
var backoffErr RecoverableError
if !errors.As(err, &backoffErr) {
return err
}