diff options
-rwxr-xr-x | aesan_alerts.rb | 14 |
1 files changed, 12 insertions, 2 deletions
diff --git a/aesan_alerts.rb b/aesan_alerts.rb index 675c047..85db083 100755 --- a/aesan_alerts.rb +++ b/aesan_alerts.rb @@ -26,7 +26,17 @@ def read_title(file_path, line) end def fetch_first_paragraph(url) - response = Net::HTTP.get_response(URI.parse(url)) + response = nil + error = nil + (1..3).each do + response = Net::HTTP.get_response(URI.parse(url)) + break + rescue StandardError => error + sleep 5 + end + if response.nil? + abort "Error al descargar URL tras 3 intentos: #{error}" + end if response.is_a?(Net::HTTPSuccess) document = Nokogiri::HTML(response.body) @@ -45,7 +55,7 @@ def fetch_first_paragraph(url) puts ps end else - warn "Error al descargar página: #{response.code} #{response.message}" + abort "Error al descargar página: #{response.code} #{response.message}" end end |