88
99from aiohttp import BasicAuth , ClientConnectorError , ClientConnectorSSLError
1010
11- from .exceptions import SimpleFinClaimError , SimpleFinInvalidClaimTokenError
11+ from .exceptions import (
12+ SimpleFinClaimError ,
13+ SimpleFinInvalidClaimTokenError ,
14+ SimpleFinInvalidAccountURLError ,
15+ SimpleFinPaymentRequiredError ,
16+ SimpleFinAuthError ,
17+ )
1218from .model import FinancialData
1319from .const import LOGGER
1420
@@ -62,16 +68,12 @@ def __init__(
6268 scheme , rest = access_url .split ("//" , 1 )
6369 try :
6470 self .auth , rest = rest .split ("@" , 1 )
65- except ValueError as e :
66- raise e
71+ except ValueError as err :
72+ raise SimpleFinInvalidAccountURLError from err
6773 self .url = scheme + "//" + rest + "/accounts"
6874 self .username , self .password = self .auth .split (":" , 1 )
6975 self .proxy : str | None = proxy
7076
71- # self.auth already is this i think..??
72- # self.auth = BasicAuth(self.username, self.password)
73- # self.session = self._create_session(auth, verify_ssl)
74-
7577 async def fetch_data (self ) -> FinancialData :
7678 """Fetch financial data from SimpleFin and return as FinancialData object."""
7779 LOGGER .debug ("Starting fetch_data in SimpleFin" )
@@ -90,14 +92,19 @@ async def fetch_data(self) -> FinancialData:
9092 response = await session .get (
9193 self .access_url + "/accounts" , ** request_params
9294 )
93- response .raise_for_status ()
95+
96+ if response .status == 402 :
97+ raise SimpleFinPaymentRequiredError ()
98+ if response .status == 403 :
99+ raise SimpleFinAuthError ()
100+
94101 data = await response .json ()
95102 LOGGER .debug (f"Received data: { data } " )
96103 financial_data : FinancialData = FinancialData .from_dict (data ) # type: ignore[attr-defined]
97104 LOGGER .debug (f"Parsed FinancialData: { financial_data } " )
98105 return financial_data
99- except (ClientConnectorError , ClientConnectorSSLError ) as e :
100- raise e
106+ except (ClientConnectorError , ClientConnectorSSLError ) as err :
107+ raise err
101108 except Exception as e :
102109 print (e )
103110 raise e
0 commit comments