From: Tom Hughes Date: Sun, 21 Mar 2021 10:21:25 +0000 (+0000) Subject: Handle errors checking for gravatars X-Git-Tag: live~2225 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/4c2e4de5c08cbc2f4c04647264eb3dcedf1ece2a?ds=sidebyside;hp=9786b716aa9b906049ecb12ee2cd07b5ec64f0f5 Handle errors checking for gravatars --- diff --git a/.rubocop_todo.yml b/.rubocop_todo.yml index cac193504..cc90d168e 100644 --- a/.rubocop_todo.yml +++ b/.rubocop_todo.yml @@ -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. diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 6aa98f7ee..e4dd1b2dc 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -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