Features:
1) Add error handling with logger and custom error message for holiday API requests; Fixes: (none); Extra: 1) Replace direct API response raising with try-except block for better robustness and logging;
This commit is contained in:
parent
7ef0dc6fa9
commit
0a9a6dfd6c
1 changed files with 9 additions and 5 deletions
|
|
@ -168,11 +168,15 @@ def process_promotions() -> tuple[bool, str]:
|
||||||
|
|
||||||
for day_offset in range(4):
|
for day_offset in range(4):
|
||||||
checked_date = date.today() + timedelta(days=day_offset)
|
checked_date = date.today() + timedelta(days=day_offset)
|
||||||
response = requests.get(
|
try:
|
||||||
f"https://holidays.abstractapi.com/v1/?api_key={config.ABSTRACT_API_KEY}&country=GB&"
|
response = requests.get(
|
||||||
f"month={checked_date.month}&day={checked_date.day}"
|
f"https://holidays.abstractapi.com/v1/?api_key={config.ABSTRACT_API_KEY}&country=GB&"
|
||||||
)
|
f"month={checked_date.month}&day={checked_date.day}"
|
||||||
response.raise_for_status()
|
)
|
||||||
|
response.raise_for_status()
|
||||||
|
except Exception as e:
|
||||||
|
logger.warning(f"Couldn't fetch holiday data for {checked_date}: {e!s}")
|
||||||
|
return False, f"Couldn't fetch holiday data for {checked_date}: {e!s}"
|
||||||
holidays = response.json()
|
holidays = response.json()
|
||||||
if holidays:
|
if holidays:
|
||||||
holiday_data = holidays[0]
|
holiday_data = holidays[0]
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue