From 8b407995dc111406ab6646a764e1e9902d62da03 Mon Sep 17 00:00:00 2001
From: Arnaud Levy <contact@arnaudlevy.com>
Date: Mon, 25 Oct 2021 12:11:29 +0200
Subject: [PATCH] robustness

---
 app/models/communication/website/imported/post.rb | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/app/models/communication/website/imported/post.rb b/app/models/communication/website/imported/post.rb
index 37787a1e6..aa83a9b22 100644
--- a/app/models/communication/website/imported/post.rb
+++ b/app/models/communication/website/imported/post.rb
@@ -100,6 +100,7 @@ class Communication::Website::Imported::Post < ApplicationRecord
     doc = Nokogiri::HTML(post.text.to_s)
     images = doc.css('img')
     if images.any?
+      begin
       url = images.first.attr('src')
       uri = URI(url)
       filename = File.basename url
@@ -107,9 +108,8 @@ class Communication::Website::Imported::Post < ApplicationRecord
       http.use_ssl = true
       http.verify_mode = OpenSSL::SSL::VERIFY_NONE
       request = Net::HTTP::Get.new(uri.request_uri)
-      begin
-        response = http.request(request)
-        post.featured_image.attach(io: StringIO.new(response.body), filename: filename, content_type: 'image/jpeg')
+      response = http.request(request)
+      post.featured_image.attach(io: StringIO.new(response.body), filename: filename, content_type: 'image/jpeg')
       rescue
       end
     end
-- 
GitLab