Skip to content

Commit 7ab050d

Browse files
committed
Fix helpers to return None when Exception is thrown
1 parent 86cf0b6 commit 7ab050d

File tree

1 file changed

+13
-6
lines changed

1 file changed

+13
-6
lines changed

notubiz/api/_helpers.py

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
from datetime import datetime
2+
from typing import Optional
23

34
def get_attribute(attributes, id) -> str:
45
attribute = [attribute for attribute in attributes if attribute["id"] == id]
@@ -10,17 +11,23 @@ def get_attribute(attributes, id) -> str:
1011

1112
return attribute[0]["value"]
1213

13-
def get_title(attributes) -> str:
14-
return get_attribute(attributes, 1)
14+
def get_title(attributes) -> Optional[str]:
15+
try:
16+
return get_attribute(attributes, 1)
17+
except Exception:
18+
return None
1519

16-
def get_description(attributes):
20+
def get_description(attributes) -> Optional[str]:
1721
try:
1822
return get_attribute(attributes, 3)
1923
except Exception:
20-
return ""
24+
return None
2125

22-
def get_location(attributes):
23-
return get_attribute(attributes, 50)
26+
def get_location(attributes) -> Optional[str]:
27+
try:
28+
return get_attribute(attributes, 50)
29+
except Exception:
30+
return None
2431

2532
def parse_date(date_string : str) -> datetime:
2633
return datetime.strptime(date_string, "%Y-%m-%d %H:%M:%S")

0 commit comments

Comments
 (0)