Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions app/commands/user/avatar_data_uri.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,13 @@ def call
return nil if external_avatar_url.blank?

external_data_uri
rescue OpenURI::HTTPError => e
# A 4xx means the host has refused or lost this user's avatar (a deleted
# account, or a host that blocks us). That is a fact about the user's data,
# so we fall back without reporting it. A 5xx may be transient, so it still
# goes to Sentry.
Sentry.capture_exception(e) unless e.io.status.first.start_with?("4")
nil
rescue StandardError => e
Sentry.capture_exception(e)
nil
Expand Down
9 changes: 9 additions & 0 deletions test/commands/user/avatar_data_uri_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,15 @@ def png_bytes = File.binread(Rails.root.join("app", "images", "favicon.png"))
assert_nil User::AvatarDataUri.(user)
end

test "returns nil without reporting when the external avatar host refuses the request" do
user = create :user, :external_avatar_url
stub_request(:get, user.attributes['avatar_url']).to_return(status: 403)

Sentry.expects(:capture_exception).never

assert_nil User::AvatarDataUri.(user)
end

test "returns nil rather than raising when the external avatar is not an image" do
user = create :user, :external_avatar_url
stub_request(:get, user.attributes['avatar_url']).to_return(
Expand Down
Loading