Skip to content

Commit

Permalink
improved error descriptions for non valid requisitions
Browse files Browse the repository at this point in the history
  • Loading branch information
dnbasta committed Mar 24, 2024
1 parent 4fc5652 commit 4c3b944
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions ynabapiimport/requisitionhandler.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from typing import List
from urllib.error import HTTPError
from uuid import uuid4

from nordigen import NordigenClient
Expand All @@ -14,11 +13,20 @@ def __init__(self, client: NordigenClient, reference: str):
self._reference = reference

def fetch_requisition(self) -> dict:
try:
results = self._client.requisition.get_requisitions()['results']
return next(r for r in results if r['status'] == 'LN' and r['reference'].split('::')[0] == self._reference)
except (HTTPError, StopIteration):
raise NoRequisitionError()

results = self._client.requisition.get_requisitions()['results']
reqs = [r for r in results if r['reference'].split('::')[0] == self._reference]
if not reqs:
raise NoRequisitionError(f"No requisition found for {self._reference}")
else:
try:
return next(r for r in reqs if r['status'] == 'LN')
except StopIteration:
try:
r = next(r for r in reqs if r['status'] == 'EX')
raise NoRequisitionError("Requisition expired")
except StopIteration:
raise NoRequisitionError(f"Requisition not valid. Current status: {[r['status'] for r in reqs]}'")

def create_requisition_auth_link(self, institution_id: str) -> str:
req_list = self._client.requisition.get_requisitions()['results']
Expand Down

0 comments on commit 4c3b944

Please sign in to comment.