Skip to content

Commit

Permalink
Extract check for retryable error into function
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonKienzler committed Mar 22, 2024
1 parent 701e753 commit 5343663
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions provider/webhook/webhook.go
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}

0 comments on commit 5343663

Please sign in to comment.