lib/carrierwave/downloader/base.rb in carrierwave-2.2.6 vs lib/carrierwave/downloader/base.rb in carrierwave-3.0.0.beta

- old
+ new

@@ -19,10 +19,11 @@ # # [url (String)] The URL where the remote file is stored # [remote_headers (Hash)] Request headers # def download(url, remote_headers = {}) + @current_download_retry_count = 0 headers = remote_headers. reverse_merge('User-Agent' => "CarrierWave/#{CarrierWave::VERSION}") uri = process_uri(url.to_s) begin if skip_ssrf_protection?(uri) @@ -40,10 +41,16 @@ end response.uri = request.uri response.value end rescue StandardError => e - raise CarrierWave::DownloadError, "could not download file: #{e.message}" + if @current_download_retry_count < @uploader.download_retry_count + @current_download_retry_count += 1 + sleep 5 + retry + else + raise CarrierWave::DownloadError, "could not download file: #{e.message}" + end end CarrierWave::Downloader::RemoteFile.new(response) end ##