]> git.openstreetmap.org Git - rails.git/commitdiff
Handle errors checking for gravatars
authorTom Hughes <tom@compton.nu>
Sun, 21 Mar 2021 10:21:25 +0000 (10:21 +0000)
committerTom Hughes <tom@compton.nu>
Sun, 21 Mar 2021 10:24:53 +0000 (10:24 +0000)
.rubocop_todo.yml
app/controllers/users_controller.rb

index cac193504b23fd2e5166998a8d07a81e50ac5cf7..cc90d168eca6d1ea37d02fdcb30da94c6c795899 100644 (file)
@@ -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.
index 6aa98f7ee508b1a083132b567b5305d07aedeaa3..e4dd1b2dc96247c30d612909f2d35502a65c311c 100644 (file)
@@ -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