Nicer error message when plaid login expires
authorMagnus Hagander <magnus@hagander.net>
Mon, 18 Mar 2024 17:54:58 +0000 (18:54 +0100)
committerMagnus Hagander <magnus@hagander.net>
Mon, 18 Mar 2024 17:54:58 +0000 (18:54 +0100)
Trap the specific error case when the login to the underlying bank
expires and give a more detailed output, since this is something that
happens on a regular basis without nothing actually being wrong.

postgresqleu/util/payment/plaid.py

index 67f483e7e81ba51862a63a53df5c5395bd5af835..93004251238f36b73099286adeb92cf44146d7f1 100644 (file)
@@ -196,6 +196,11 @@ class Plaid(BaseManagedBankPayment):
                 param['cursor'] = self.method.config['sync_cursor']
 
             r = self.session.post('{}transactions/sync'.format(self.ROOTURL), json=param)
+            if r.status_code == 400:
+                j = r.json()
+                if j['error_code'] == 'ITEM_LOGIN_REQUIRED':
+                    raise Exception("Login refresh needed for plaid account: {}".format(j['error_message']))
+
             r.raise_for_status()
 
             j = r.json()