Skip to content

Commit 14375df

Browse files
iHiDclaude
andauthored
Handle 404 errors gracefully in AvatarsController (#8346)
When a user's avatar_url points to a dead link, the open-uri fetch raises OpenURI::HTTPError. Previously this was caught by the broad StandardError rescue, reported to Bugsnag (noise), and returned a 500. Now we specifically rescue OpenURI::HTTPError and fall back to serving the placeholder avatar with a short cache TTL (5 minutes), so users still see an avatar and the error doesn't flood Bugsnag. Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 4180fea commit 14375df

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

app/controllers/avatars_controller.rb

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,11 @@ def show
2929
send_data data, type: content_type, disposition: 'inline'
3030
rescue ActiveRecord::RecordNotFound
3131
head :not_found
32+
rescue OpenURI::HTTPError
33+
url = "#{Exercism.config.website_icons_host}/placeholders/user-avatar.svg"
34+
file = URI.parse(url).open
35+
expires_in 5.minutes, public: true
36+
send_data file.read, type: file.content_type, disposition: 'inline'
3237
rescue StandardError => e
3338
Bugsnag.notify(e)
3439
head :internal_server_error

0 commit comments

Comments
 (0)