Stu Mason
Stu Mason

Activity

Pull Request Merged

PR #20 merged: fix: Handle partial sync failures gracefully (issue #19)

Summary

Fixes #19 - When one Polar API endpoint returns an error (e.g., 403 on sleep due to missing data sharing consents), the sync now continues with other endpoints instead of failing entirely.

Changes

  • SyncResult dataclass - New return type that tracks both successful record counts and per-endpoint errors
  • Per-endpoint error handling - Each _sync_* call is wrapped in try/except so failures don't stop other syncs
  • Actionable error messages - 403 errors now include guidance: "Check consent settings at https://account.polar.com or re-authenticate with Polar"
  • Partial success UI - New sync_partial.html template shows both synced data and errors in a yellow warning banner
  • SyncOrchestrator updates - Properly tracks partial success status in SyncLog

Before

If sleep endpoint returned 403, entire sync failed - no data synced at all.

After

If sleep returns 403:

  • Error captured with actionable message
  • Other endpoints (recharge, activity, exercises, etc.) continue syncing
  • UI shows partial success with details on what failed and why

Test plan

  • Unit tests added for new behavior (tests/test_sync_error_handling.py)
  • All 77 existing tests pass
  • Type checking passes (mypy)
  • Linting passes (ruff)
  • Manual test with real 403 error (need account with limited scopes)
+696
additions
-92
deletions
14
files changed