feat: improve GoCardless error handling

Handle 409 when retriving transactions, which signals the account data
is still being processed, and 429, which signals the rate lite was
exceeded.
This commit is contained in:
Luís Murta 2026-01-01 19:05:37 +00:00
parent 46f6ee2af7
commit cee5fe77e1
Signed by: satprog
GPG Key ID: 169EF1BBD7049F94

View File

@ -61,6 +61,21 @@ class NordigenClient:
retries += 1 retries += 1
print(f"Request #{retries} timed-out, retrying in 1s") print(f"Request #{retries} timed-out, retrying in 1s")
time.sleep(1) time.sleep(1)
except requests.HTTPError as e:
if (
e.response.status_code == 409
and e.response.type == "AccountProcessing"
):
timeout = 1
while account.get_metadata()["status"] != "READY":
print(f"Waiting for status ready, retrying in {timeout}s")
time.sleep(timeout)
timeout *= 2
elif e.response.status_code == 429:
print("Rate limit exceeded for today, aborting")
break
else:
raise DownloadError(e)
if not downloaded: if not downloaded:
print(f"Couldn't download transactions for {account.get_metadata()}") print(f"Couldn't download transactions for {account.get_metadata()}")