Skip to content

Open-source personal finance manager. Self-hosted, privacy-first.

fix(sync): handle bank rate limits (HTTP 429) gracefully (#269)

Tássio Noronha4b26fe4327b2
diff --git a/backend/app/providers/base.py b/backend/app/providers/base.py
index cc25ef1a..a1a4f711 100644
--- a/backend/app/providers/base.py
+++ b/backend/app/providers/base.py
@@ -151,6 +151,16 @@ class ProviderUserActionRequired(Exception):
self.help_url = help_url
+class ProviderRateLimited(Exception):
+ """Raised when the upstream bank/aggregator is throttling data requests.
+
+ Transient and outside the user's control — PSD2 caps unattended account
+ access (commonly ~4/day per resource), so a burst of syncs returns HTTP
+ 429. The connection is healthy; callers should skip this run and retry
+ later rather than flag it as errored.
+ """
+
+
class FxRateProvider(ABC):
"""Abstract interface for FX rate providers."""
diff --git a/backend/app/providers/enable_banking.py b/backend/app/providers/enable_banking.py
index 04fe6628..0813d802 100644
--- a/backend/app/providers/enable_banking.py
+++ b/backend/app/providers/enable_banking.py
@@ -30,6 +30,7 @@ from app.providers.base import (
ConnectionData,
InstitutionData,
InstitutionListData,
+ ProviderRateLimited,
ProviderUserActionRequired,
SessionExpiredError,
TransactionData,
@@ -244,6 +245,13 @@ class EnableBankingProvider(BankProvider):
raise SessionExpiredError(
f"Enable Banking returned {resp.status_code} for {path}"
)
+ if resp.status_code == 429:
+ # The bank (ASPSP) is throttling us — transient, not a broken
+ # connection. Surface a distinct type so sync can skip-and-retry
+ # instead of erroring the connection.
+ raise ProviderRateLimited(
+ f"Enable Banking {method} {path} → 429: {resp.text[:200]}"
+ )
if resp.status_code >= 400:
raise httpx.HTTPStatusError(
f"Enable Banking {method} {path} → {resp.status_code}: {resp.text[:300]}",
diff --git a/backend/app/services/connection_service.py b/backend/app/services/connection_service.py
index fc887bde..b1297b48 100644
--- a/backend/app/services/connection_service.py
+++ b/backend/app/services/connection_service.py
@@ -22,6 +22,7 @@ from app.models.user import User
from app.providers import get_provider
from app.providers.base import (
HoldingData,
+ ProviderRateLimited,
ProviderUserActionRequired,
SessionExpiredError,
)
@@ -1375,6 +1376,18 @@ async def sync_connection(
# so the API layer can surface the specific code to the UI.
await session.rollback()
raise
+ except ProviderRateLimited:
+ # The bank/aggregator is throttling data requests (PSD2 caps unattended
+ # access, commonly ~4/day). The connection is healthy, so don't error
+ # it or 500 the request — skip this run, keep it active, and leave
+ # last_sync_at untouched so the next sync retries the same window.
+ await session.rollback()
+ async with session.begin():
+ conn = await session.get(BankConnection, connection_id)
+ if conn and conn.status != "expired":
+ conn.status = "active"
+ refreshed = await session.get(BankConnection, connection_id)
+ return refreshed, 0
except Exception:
# Mark connection as errored so UI shows reconnect banner
await session.rollback()