diff --git a/avroregistry/registry.go b/avroregistry/registry.go index f53022d..4f45c9a 100644 --- a/avroregistry/registry.go +++ b/avroregistry/registry.go @@ -198,19 +198,23 @@ func (r *Registry) doRequest(req *http.Request, result interface{}) error { if err == nil { return nil } - if !attempt.More() { - return &UnavailableError{err} - } - if err, ok := err.(*apiError); ok && err.StatusCode != http.StatusInternalServerError { - // It's not a 5xx error. We want to retry on 5xx + if err, ok := err.(*apiError); ok { + // We want to retry on 5xx // errors, because the Confluent Avro registry // can occasionally return them as a matter of // course (and there could also be an // unavailable service that we're reaching // through a proxy). - if !attempt.More() { - return &UnavailableError{err} + switch err.StatusCode { + case http.StatusInternalServerError: + if !attempt.More() { + return &UnavailableError{err} + } + default: + return err } + } + if !attempt.More() { return err } } diff --git a/avroregistry/registry_test.go b/avroregistry/registry_test.go index d929d54..43858e2 100644 --- a/avroregistry/registry_test.go +++ b/avroregistry/registry_test.go @@ -340,7 +340,7 @@ func TestRetryOn500(t *testing.T) { // an error. failCount = 5 err = registry.SetCompatibility(context.Background(), "x", avro.BackwardTransitive) - c.Assert(err, qt.ErrorMatches, `Avro registry error \(code 50001; HTTP status 500\): Failed to update compatibility level`) + c.Assert(err, qt.ErrorMatches, `schema registry unavailability caused by: Avro registry error \(code 50001; HTTP status 500\): Failed to update compatibility level`) } func TestNoRetryOnNon5XXStatus(t *testing.T) { @@ -392,7 +392,7 @@ func TestUnavailableError(t *testing.T) { }) c.Assert(err, qt.Equals, nil) err = registry.SetCompatibility(context.Background(), "x", avro.BackwardTransitive) - c.Assert(err, qt.ErrorMatches, `cannot unmarshal JSON error response from .*/config/x: unexpected content type text/html; want application/json; content: 502 Proxy Error; Proxy Error; The whole world is bogus`) + c.Assert(err, qt.ErrorMatches, `schema registry unavailability caused by: cannot unmarshal JSON error response from .*/config/x: unexpected content type text/html; want application/json; content: 502 Proxy Error; Proxy Error; The whole world is bogus`) } var schemaEquivalenceTests = []struct {