From 75f9467a16016171ed460147683c90fa720a38d3 Mon Sep 17 00:00:00 2001 From: Jeremy Walker Date: Wed, 28 Oct 2026 21:04:49 +0900 Subject: [PATCH] Stop reporting refused external avatars to Sentry When an external avatar host returns a 4xx, User::AvatarDataUri now returns nil without reporting it. 5xx responses, timeouts and other errors are still reported. Co-Authored-By: Claude Opus 5.5 --- app/commands/user/avatar_data_uri.rb | 7 +++++++ test/commands/user/avatar_data_uri_test.rb | 9 +++++++++ 2 files changed, 16 insertions(+) diff --git a/app/commands/user/avatar_data_uri.rb b/app/commands/user/avatar_data_uri.rb index 02ec131e16..4cfb7de1c7 100644 --- a/app/commands/user/avatar_data_uri.rb +++ b/app/commands/user/avatar_data_uri.rb @@ -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 diff --git a/test/commands/user/avatar_data_uri_test.rb b/test/commands/user/avatar_data_uri_test.rb index 9b89f0db91..f352180c16 100644 --- a/test/commands/user/avatar_data_uri_test.rb +++ b/test/commands/user/avatar_data_uri_test.rb @@ -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(