Skip to content

Commit

Permalink
Handle errors checking for gravatars
Browse files Browse the repository at this point in the history
  • Loading branch information
tomhughes committed Mar 21, 2021
1 parent 978ba72 commit 9078e1d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 5 deletions.
2 changes: 1 addition & 1 deletion .rubocop_todo.yml
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ Metrics/BlockNesting:
# Offense count: 24
# Configuration parameters: CountComments, CountAsOne.
Metrics/ClassLength:
Max: 582
Max: 587

# Offense count: 52
# Configuration parameters: IgnoredMethods.
Expand Down
14 changes: 10 additions & 4 deletions app/controllers/users_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -753,11 +753,17 @@ def gravatar_enable(user)
# code from example https://en.gravatar.com/site/implement/images/ruby/
return false if user.avatar.attached?

hash = Digest::MD5.hexdigest(user.email.downcase)
url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
response = OSM.http_client.get(URI.parse(url))
begin
hash = Digest::MD5.hexdigest(user.email.downcase)
url = "https://www.gravatar.com/avatar/#{hash}?d=404" # without d=404 we will always get an image back
response = OSM.http_client.get(URI.parse(url))
available = response.success?
rescue StandardError
available = false
end

oldsetting = user.image_use_gravatar
user.image_use_gravatar = response.success?
user.image_use_gravatar = available
oldsetting != user.image_use_gravatar
end

Expand Down

0 comments on commit 9078e1d

Please sign in to comment.