FIX: Don't raise an error when the upload can't be retrieved

This commit is contained in:
Robin Ward 2017-05-24 13:29:50 -04:00
parent e8c89b4535
commit 87ac758f05

View File

@ -21,6 +21,7 @@ class UserAvatar < ActiveRecord::Base
max = Discourse.avatar_sizes.max max = Discourse.avatar_sizes.max
gravatar_url = "http://www.gravatar.com/avatar/#{email_hash}.png?s=#{max}&d=404" gravatar_url = "http://www.gravatar.com/avatar/#{email_hash}.png?s=#{max}&d=404"
tempfile = FileHelper.download(gravatar_url, SiteSetting.max_image_size_kb.kilobytes, "gravatar") tempfile = FileHelper.download(gravatar_url, SiteSetting.max_image_size_kb.kilobytes, "gravatar")
if tempfile
upload = UploadCreator.new(tempfile, 'gravatar.png', origin: gravatar_url, type: "avatar").create_for(user_id) upload = UploadCreator.new(tempfile, 'gravatar.png', origin: gravatar_url, type: "avatar").create_for(user_id)
if gravatar_upload_id != upload.id if gravatar_upload_id != upload.id
@ -28,6 +29,7 @@ class UserAvatar < ActiveRecord::Base
self.gravatar_upload = upload self.gravatar_upload = upload
save! save!
end end
end
rescue OpenURI::HTTPError rescue OpenURI::HTTPError
save! save!
rescue SocketError rescue SocketError