fix: improve error handling in NotionExtractor data fetching (#12182)

Signed-off-by: -LAN- <laipz8200@outlook.com>
This commit is contained in:
-LAN- 2024-12-29 11:53:09 +08:00 committed by GitHub
parent 716bb8574d
commit 8d15c8cfbf
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -138,6 +138,7 @@ class NotionExtractor(BaseExtractor):
block_url = BLOCK_CHILD_URL_TMPL.format(block_id=page_id) block_url = BLOCK_CHILD_URL_TMPL.format(block_id=page_id)
while True: while True:
query_dict: dict[str, Any] = {} if not start_cursor else {"start_cursor": start_cursor} query_dict: dict[str, Any] = {} if not start_cursor else {"start_cursor": start_cursor}
try:
res = requests.request( res = requests.request(
"GET", "GET",
block_url, block_url,
@ -148,7 +149,13 @@ class NotionExtractor(BaseExtractor):
}, },
params=query_dict, params=query_dict,
) )
if res.status_code != 200:
raise ValueError(f"Error fetching Notion block data: {res.text}")
data = res.json() data = res.json()
except requests.RequestException as e:
raise ValueError("Error fetching Notion block data") from e
if "results" not in data or not isinstance(data["results"], list):
raise ValueError("Error fetching Notion block data")
for result in data["results"]: for result in data["results"]:
result_type = result["type"] result_type = result["type"]
result_obj = result[result_type] result_obj = result[result_type]