Skip to content

fix: error handling for blog article retrieval and improve retry error logging#16118

Open
Onibenjo wants to merge 4 commits intomainfrom
fix/sentry-connection-errors
Open

fix: error handling for blog article retrieval and improve retry error logging#16118
Onibenjo wants to merge 4 commits intomainfrom
fix/sentry-connection-errors

Conversation

@Onibenjo
Copy link
Copy Markdown
Contributor

@Onibenjo Onibenjo commented Mar 12, 2026

BlogRedirects.dispatch_request has no error handling around the WordPress API call
(admin.insights.ubuntu.com). When the API returns repeated 503s, the
ConnectionError propagates unhandled — resulting in noisy unhandled exceptions in Sentry.

Done

  • webapp/views.py: Wrap the get_article() call in BlogRedirects with a try/except
    for ConnectionError, Timeout, and HTTPError.
  • webapp/app.py: Extend sentry_before_send to sample out 95% of blog/WordPress API
    retry errors matching /wp-json/wp/v2 with 500/502/503/504 status codes.
  • tests/test_sentry_filtering.py: Add 5 tests covering the new blog API sampling
    branch — drops, keeps, ConnectionError/MaxRetryError variants, and a negative case
    for non-5xx errors.

QA

  • Open the DEMO
  • Alternatively, check out this feature branch
  • Run the site using the command ./run serve or dotrun
  • View the site locally in your web browser at: http://0.0.0.0:8001/
    • Be sure to test on mobile, tablet and desktop screen sizes
  • [List additional steps to QA the new features or prove the bug has been resolved]

Issue / Card

Fixes #

Screenshots

[If relevant, please include a screenshot.]

Help

QA steps - Commit guidelines

Copilot AI review requested due to automatic review settings March 12, 2026 15:29
@webteam-app
Copy link
Copy Markdown

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 12, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 2 lines in your changes missing coverage. Please review.
✅ Project coverage is 48.11%. Comparing base (057cd4a) to head (929387d).
⚠️ Report is 3 commits behind head on main.

Files with missing lines Patch % Lines
webapp/views.py 60.00% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16118      +/-   ##
==========================================
+ Coverage   48.09%   48.11%   +0.01%     
==========================================
  Files          37       37              
  Lines        5842     5848       +6     
==========================================
+ Hits         2810     2814       +4     
- Misses       3032     3034       +2     
Files with missing lines Coverage Δ
webapp/app.py 85.83% <100.00%> (+0.12%) ⬆️
webapp/views.py 44.75% <60.00%> (-0.04%) ⬇️
🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves resilience and observability around blog article retrieval by handling upstream request failures more gracefully and by reducing Sentry noise from repeated retry-related exceptions.

Changes:

  • Add request exception handling around blog article retrieval and return a 502 on upstream failures.
  • Extend Sentry before_send sampling to drop most retry errors originating from the blog/WordPress API.
  • Update inline comments in Sentry filtering logic to reflect the expanded scope (security + blog).

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 5 comments.

File Description
webapp/views.py Wrap blog article retrieval in a try/except and respond with 502 for upstream request failures.
webapp/app.py Add Sentry sampling logic for retry errors coming from admin.insights.ubuntu.com.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Timeout,
HTTPError,
):
return flask.make_response(flask.render_template("500.html"), 502)
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The code indicates it's a server downtimeand not a server code error

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

You can also share your feedback on Copilot code review. Take the survey.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants