Handle errors checking for gravatars
This commit is contained in:
parent
9786b716aa
commit
4c2e4de5c0
2 changed files with 11 additions and 5 deletions
|
@ -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.
|
||||
|
|
|
@ -753,11 +753,17 @@ class UsersController < ApplicationController
|
|||
# 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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue