Skip to content

Commit 78eb987

Browse files
authored
Merge pull request #12 from CyberCRI/fix-wikipedia-updater-compare-error
Catch KeyError in case of unexpected response from Wikipedia API
2 parents 1b954b4 + 63875ae commit 78eb987

File tree

2 files changed

+5
-2
lines changed

2 files changed

+5
-2
lines changed

welearn_datastack/modules/wikipedia_updater.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,9 @@ def compare_with_current_version(document: WeLearnDocument) -> bool:
8181
}
8282

8383
resp = session.get(url=url, params=params)
84-
data = resp.json()["compare"]
84+
try:
85+
data = resp.json()["compare"]
86+
except KeyError as e:
87+
raise KeyError("Unexpected response from Wikipedia API") from e
8588

8689
return data["diffsize"] > 0.05 * data["fromsize"] # 5% threshold

welearn_datastack/nodes_workflow/WikipediaUpdater/wikipedia_updater.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,7 @@ def main() -> None:
6464
title=Step.URL_RETRIEVED.value,
6565
)
6666
)
67-
except ValueError as e:
67+
except (ValueError, KeyError) as e:
6868
logger.error("Error while comparing document '%s': %s", wld.title, e)
6969
continue
7070

0 commit comments

Comments
 (0)