Skip to content

Commit f40dbf4

Browse files
committed
Update exception handling to use structured QuantifyingException approach
1 parent 1cdf721 commit f40dbf4

1 file changed

Lines changed: 6 additions & 14 deletions

File tree

scripts/1-fetch/doaj_fetch.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -199,20 +199,12 @@ def process_journals(session, args):
199199
response = session.get(url, params=params, timeout=30)
200200
response.raise_for_status()
201201
data = response.json()
202-
except requests.exceptions.RequestException as e:
203-
if hasattr(e, "response") and e.response.status_code == 400:
204-
LOGGER.info(f"Reached end of available data at page {page}")
205-
break
206-
else:
207-
LOGGER.error(f"Failed to fetch journals page {page}: {e}")
208-
raise shared.QuantifyingException(
209-
f"Critical API error on page {page}: {e}", exit_code=1
210-
)
211-
except (ValueError, KeyError) as e:
212-
LOGGER.error(f"Failed to parse JSON response on page {page}: {e}")
213-
raise shared.QuantifyingException(
214-
f"Critical JSON parsing error on page {page}: {e}", exit_code=1
215-
)
202+
except requests.HTTPError as e:
203+
raise shared.QuantifyingException(f"HTTP Error: {e}", 1)
204+
except requests.RequestException as e:
205+
raise shared.QuantifyingException(f"Request Exception: {e}", 1)
206+
except KeyError as e:
207+
raise shared.QuantifyingException(f"KeyError: {e}", 1)
216208

217209
try:
218210
results = data.get("results", [])

0 commit comments

Comments
 (0)