From a88cae299a47ce4e63be3cfaee5a3ecec130f1e7 Mon Sep 17 00:00:00 2001 From: Simon Kienzler Date: Fri, 22 Mar 2024 10:31:33 +0100 Subject: [PATCH] Extract check for retryable error into function --- provider/webhook/webhook.go | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/provider/webhook/webhook.go b/provider/webhook/webhook.go index 6bfe4409d..12c24dc10 100644 --- a/provider/webhook/webhook.go +++ b/provider/webhook/webhook.go @@ -182,7 +182,7 @@ func (p WebhookProvider) Records(ctx context.Context) ([]*endpoint.Endpoint, err recordsErrorsGauge.Inc() log.Debugf("Failed to get records with code %d", resp.StatusCode) err := fmt.Errorf("failed to get records with code %d", resp.StatusCode) - if resp.StatusCode >= http.StatusInternalServerError { + if isRetryableError(resp.StatusCode) { return nil, provider.NewSoftError(err) } return nil, err @@ -230,7 +230,7 @@ func (p WebhookProvider) ApplyChanges(ctx context.Context, changes *plan.Changes applyChangesErrorsGauge.Inc() log.Debugf("Failed to apply changes with code %d", resp.StatusCode) err := fmt.Errorf("failed to apply changes with code %d", resp.StatusCode) - if resp.StatusCode >= http.StatusInternalServerError { + if isRetryableError(resp.StatusCode) { return provider.NewSoftError(err) } return err @@ -280,7 +280,7 @@ func (p WebhookProvider) AdjustEndpoints(e []*endpoint.Endpoint) ([]*endpoint.En adjustEndpointsErrorsGauge.Inc() log.Debugf("Failed to AdjustEndpoints with code %d", resp.StatusCode) err := fmt.Errorf("failed to AdjustEndpoints with code %d", resp.StatusCode) - if resp.StatusCode >= http.StatusInternalServerError { + if isRetryableError(resp.StatusCode) { return nil, provider.NewSoftError(err) } return nil, err @@ -299,3 +299,8 @@ func (p WebhookProvider) AdjustEndpoints(e []*endpoint.Endpoint) ([]*endpoint.En func (p WebhookProvider) GetDomainFilter() endpoint.DomainFilter { return p.DomainFilter } + +// isRetryableError returns true for HTTP status codes between 500 and 510 (inclusive) +func isRetryableError(statusCode int) bool { + return statusCode >= http.StatusInternalServerError && statusCode <= http.StatusNotExtended +}