Skip to content

Handle 404 errors gracefully in AvatarsController#8346

Merged
iHiD merged 1 commit intomainfrom
ihid/fix-avatar-404-handling
Feb 8, 2026
Merged

Handle 404 errors gracefully in AvatarsController#8346
iHiD merged 1 commit intomainfrom
ihid/fix-avatar-404-handling

Conversation

@iHiD
Copy link
Copy Markdown
Member

@iHiD iHiD commented Feb 8, 2026

Summary

  • When a user's avatar_url points to a dead link (deleted GitHub avatar, etc.), the open-uri fetch raises OpenURI::HTTPError
  • Previously caught by the broad StandardError rescue — reported to Bugsnag (noise) and returned HTTP 500 (broken image)
  • Now specifically rescues OpenURI::HTTPError and falls back to serving the placeholder avatar with a short cache TTL (5 minutes)

Test plan

  • Verify rubocop passes on app/controllers/avatars_controller.rb
  • Verify that valid avatar URLs still work normally with 5-year cache
  • Verify that a 404 avatar URL serves the placeholder SVG with 5-minute cache

🤖 Generated with Claude Code

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>
@iHiD iHiD merged commit 14375df into main Feb 8, 2026
41 checks passed
@iHiD iHiD deleted the ihid/fix-avatar-404-handling branch February 8, 2026 13:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant