Skip to content

Commit 39a6b53

Browse files
authored
Handle Not Found Proposal Gracfully (#86)
* first try * . * .
1 parent b01e329 commit 39a6b53

File tree

3 files changed

+26
-3
lines changed

3 files changed

+26
-3
lines changed

src/quorum/apis/governance/aave_governance.py

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,22 @@
2424
}
2525

2626

27+
class ProposalNotFoundException(Exception):
28+
def __init__(
29+
self, proposal_id: int, project_name: str, response: requests.Response
30+
):
31+
super().__init__()
32+
self.proposal_id = proposal_id
33+
self.project_name = project_name
34+
self.response = response
35+
36+
def __str__(self):
37+
return (
38+
f"Proposal id {self.proposal_id} for {self.project_name} could not be found "
39+
f"at url {self.response.url} (error code {self.response.status_code})"
40+
)
41+
42+
2743
class AaveGovernanceAPI:
2844
"""
2945
A utility class to interact with the BGD governance cache and retrieve
@@ -45,7 +61,10 @@ def get_proposal_data(self, proposal_id: int) -> BGDProposalData:
4561
"""
4662
proposal_data_link = f"{PROPOSALS_URL}/{proposal_id}.json"
4763
resp = self.session.get(proposal_data_link)
48-
resp.raise_for_status()
64+
try:
65+
resp.raise_for_status()
66+
except requests.HTTPError as e:
67+
raise ProposalNotFoundException(proposal_id, "Aave", e.response) from e
4968

5069
raw_json = resp.json()
5170
# Parse into our data model

src/quorum/auto_report/aave_tags.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,6 @@ def get_aave_tags(proposal_id: int) -> dict[str, Any]:
6565
"""
6666
api = AaveGovernanceAPI()
6767
bgd_data: BGDProposalData = api.get_proposal_data(proposal_id)
68-
6968
# Safely unwrap fields (some might be None).
7069
ipfs_data: IPFSData = bgd_data.ipfs or IPFSData()
7170
proposal_data: ProposalData = bgd_data.proposal or ProposalData()

src/quorum/entry_points/implementations/create_report.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import quorum.auto_report.aave_tags as aave_tags
77
import quorum.utils.pretty_printer as pp
8+
from quorum.apis.governance.aave_governance import ProposalNotFoundException
89

910

1011
def run_create_report(args: argparse.Namespace):
@@ -40,7 +41,11 @@ def run_create_report(args: argparse.Namespace):
4041
pp.pprint(
4142
f"Retrieving tag information for proposal {args.proposal_id}", pp.Colors.INFO
4243
)
43-
tags = aave_tags.get_aave_tags(args.proposal_id)
44+
try:
45+
tags = aave_tags.get_aave_tags(args.proposal_id)
46+
except ProposalNotFoundException as e:
47+
pp.pprint(e, pp.Colors.FAILURE)
48+
return
4449
pp.pprint("Tag information retrieved", pp.Colors.INFO)
4550

4651
report = template.render(tags)

0 commit comments

Comments
 (0)