Rescue exceptions caused by FetchLinkCardService (#4045)
parent
be94f9e35d
commit
a6d02cff36
|
@ -10,7 +10,11 @@ module Remotable
|
||||||
method_name = "#{attribute_name}=".to_sym
|
method_name = "#{attribute_name}=".to_sym
|
||||||
|
|
||||||
define_method method_name do |url|
|
define_method method_name do |url|
|
||||||
|
begin
|
||||||
parsed_url = Addressable::URI.parse(url).normalize
|
parsed_url = Addressable::URI.parse(url).normalize
|
||||||
|
rescue Addressable::URI::InvalidURIError
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? || self[attribute_name] == url
|
return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? || self[attribute_name] == url
|
||||||
|
|
||||||
|
@ -26,7 +30,7 @@ module Remotable
|
||||||
send("#{attachment_name}_file_name=", filename)
|
send("#{attachment_name}_file_name=", filename)
|
||||||
|
|
||||||
self[attribute_name] = url if has_attribute?(attribute_name)
|
self[attribute_name] = url if has_attribute?(attribute_name)
|
||||||
rescue HTTP::TimeoutError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError => e
|
rescue HTTP::TimeoutError, HTTP::ConnectionError, OpenSSL::SSL::SSLError, Paperclip::Errors::NotIdentifiedByImageMagickError, Addressable::URI::InvalidURIError => e
|
||||||
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
|
Rails.logger.debug "Error fetching remote #{attachment_name}: #{e}"
|
||||||
nil
|
nil
|
||||||
end
|
end
|
||||||
|
|
|
@ -18,6 +18,8 @@ class FetchLinkCardService < BaseService
|
||||||
return if res.code != 200 || res.mime_type != 'text/html'
|
return if res.code != 200 || res.mime_type != 'text/html'
|
||||||
|
|
||||||
attempt_opengraph(card, url) unless attempt_oembed(card, url)
|
attempt_opengraph(card, url) unless attempt_oembed(card, url)
|
||||||
|
rescue HTTP::ConnectionError, OpenSSL::SSL::SSLError
|
||||||
|
nil
|
||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
Loading…
Reference in New Issue