fix(announcements): degrade 404 on /announcements/latest to null instead of erroring#4417
Conversation
…ead of erroring GET /announcements/latest returning 404 in prod (backend deploy gap, tracked separately in tinyhumansai/backend#1064) was funneled into report_error at two layers - authed_json's generic non-2xx handling (TAURI-RUST-HW0) and the RPC dispatch re-wrap (TAURI-RUST-KHX) - for a purely cosmetic, best-effort fetch that should never be worth an error, let alone two. Mirror the existing BackendApiError::MessageNotFound precedent: 404 on this one route now surfaces a typed AnnouncementNotFound error that authed_json does not report to Sentry, and announcements::ops::get_latest_announcement degrades it to a null result matching the "no announcement" contract the caller already documents. Any other failure (5xx, malformed response, session expiry) still propagates and still reaches Sentry. Fixes tinyhumansai#4401
There was a problem hiding this comment.
Pull request overview
Hardens the Rust client’s best-effort announcements fetch so that a backend 404 on GET /announcements/latest is treated as “no announcement” (null) instead of bubbling up as an error that gets reported to Sentry (previously double-reported via both authed_json and JSON-RPC dispatch).
Changes:
- Introduces a typed
BackendApiError::AnnouncementNotFoundfor scoped 404 handling onGET /announcements/latest. - Updates announcements ops to fold that typed 404 into
Value::Nullwhile preserving all other error propagation viaflatten_authed_error. - Adds Rust tests validating the new typed error behavior and non-misclassification on adjacent paths.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
src/openhuman/announcements/ops.rs |
Intercepts typed announcement 404 and degrades to null to match the best-effort contract. |
src/api/rest.rs |
Adds AnnouncementNotFound and emits it from authed_json for the specific announcements endpoint to avoid report_error noise. |
src/api/rest_tests.rs |
Adds coverage for the new typed 404 behavior and ensures nearby paths aren’t misclassified. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Copilot review on PR tinyhumansai#4417 flagged that the exact url.path() == "/announcements/latest" check would miss the route when the resolved URL carries a base-path prefix (e.g. a BACKEND_URL override resolving to /api/v1/announcements/latest), falling through to the generic non-2xx report_error path this PR exists to avoid. Mirror parse_message_path's existing sliding-window/suffix tolerance (OPENHUMAN-TAURI-R7) with a new is_announcements_latest_path helper that matches on the last two path segments instead of the full path.
|
Note Currently processing new changes in this PR. This may take a few minutes, please wait... ⚙️ Run configurationConfiguration used: Organization UI Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (3)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Caution Failed to replace (edit) comment. This is likely due to insufficient permissions or the comment being deleted. Error details |
Summary
GET /announcements/latestreturning 404 in prod (a backend deploy gap tracked separately intinyhumansai/backend#1064) was being funneled intoreport_errorat two layers:authed_json's generic non-2xx handling (SentryTAURI-RUST-HW0)core/jsonrpc.rs(SentryTAURI-RUST-KHX)One 404 → two Sentry events, ~452 events / 19 users, for a purely cosmetic, best-effort announcement fetch that
announcementService.tsalready documents as "a missing announcement is never worth surfacing an error for."Fix
Mirrors the existing
BackendApiError::MessageNotFoundprecedent insrc/api/rest.rs:BackendApiError::AnnouncementNotFound, a typed error for 404 onGET /announcements/latestspecifically (exact-path + method match, scoped — not a blanket demotion of all 404s).authed_jsonnow returns this typed error for that one route instead of falling through to the generic non-2xxreport_errorpath.announcements::ops::get_latest_announcementintercepts it and degrades toValue::Null, matching the function's own documented contract ("the backend returns the announcement object ornullwhen nothing qualifies; both pass through verbatim").flatten_authed_errorand still reaches Sentry — this fix does not suppress genuine failures.Tests
authed_json_surfaces_announcement_not_found_on_404— 404 on/announcements/latestsurfaces the typed error.authed_json_only_classifies_get_announcements_latest_as_not_found— a 404 on a different/adjacent path is not misclassified (defense-in-depth).flatten_authed_error_does_not_swallow_announcement_not_found— the typed error still round-trips correctly if it ever reachesflatten_authed_errordirectly.announcement_not_found_error_is_detected/other_backend_errors_are_not_announcement_not_found— network-free unit tests for the downcast logic inops.rs.Related
tinyhumansai/backend#1064