diff --git a/app/jobs/regular/pull_hotlinked_images.rb b/app/jobs/regular/pull_hotlinked_images.rb index 4883068c1a0..939d7bc50c2 100644 --- a/app/jobs/regular/pull_hotlinked_images.rb +++ b/app/jobs/regular/pull_hotlinked_images.rb @@ -44,6 +44,7 @@ module Jobs follow_redirect: true ) rescue Discourse::InvalidParameters + log(:error, "InvalidParameters while downloading hotlinked image (#{src}) for post: #{post_id}") end if hotlinked if File.size(hotlinked.path) <= @max_size @@ -87,7 +88,7 @@ module Jobs raw.gsub!(/^#{escaped_src}(\s?)$/) { "#{$1}" } end rescue => e - log(:error, "Failed to pull hotlinked image: #{src} post:#{post_id}\n" + e.message + "\n" + e.backtrace.join("\n")) + log(:error, "Failed to pull hotlinked image (#{src}) post: #{post_id}\n" + e.message + "\n" + e.backtrace.join("\n")) end end diff --git a/lib/file_helper.rb b/lib/file_helper.rb index be727230d04..aacb056b633 100644 --- a/lib/file_helper.rb +++ b/lib/file_helper.rb @@ -4,6 +4,13 @@ require "open-uri" class FileHelper + def self.log(log_level, message) + Rails.logger.public_send( + log_level, + "#{RailsMultisite::ConnectionManagement.current_db}: #{message}" + ) + end + def self.is_image?(filename) filename =~ images_regexp end @@ -23,7 +30,11 @@ class FileHelper max_redirects: follow_redirect ? 5 : 1, skip_rate_limit: skip_rate_limit ).resolve - return unless uri.present? + + unless uri.present? + log(:error, "FinalDestination did not work for: #{url}") + return + end downloaded = uri.open("rb", read_timeout: read_timeout)