diff --git a/v2/internal/runner/nucleicloud/cloud.go b/v2/internal/runner/nucleicloud/cloud.go index 9cad856a..8557b686 100644 --- a/v2/internal/runner/nucleicloud/cloud.go +++ b/v2/internal/runner/nucleicloud/cloud.go @@ -2,6 +2,7 @@ package nucleicloud import ( "bytes" + "context" "fmt" "io" "net/http" @@ -27,10 +28,21 @@ const ( resultSize = 100 ) +// HTTPErrorRetryPolicy is to retry for HTTPCodes >= 500. +func HTTPErrorRetryPolicy() func(ctx context.Context, resp *http.Response, err error) (bool, error) { + return func(ctx context.Context, resp *http.Response, err error) (bool, error) { + if resp.StatusCode >= http.StatusInternalServerError { + return true, errors.New(resp.Status) + } + return retryablehttp.CheckRecoverableErrors(ctx, resp, err) + } +} + // New returns a nuclei-cloud API client func New(baseURL, apiKey string) *Client { options := retryablehttp.DefaultOptionsSingle options.Timeout = 15 * time.Second + options.CheckRetry = HTTPErrorRetryPolicy() client := retryablehttp.NewClient(options) baseAppURL := baseURL