mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-06-28 21:49:40 +02:00
fix(backend): Add error handling for invalid pagination cursor in NotionHistoryConnector to ensure graceful continuation of data fetching
This commit is contained in:
parent
c6d25ed7d8
commit
59d5bf9aa5
1 changed files with 24 additions and 10 deletions
|
|
@ -465,19 +465,33 @@ class NotionHistoryConnector:
|
||||||
cursor = None
|
cursor = None
|
||||||
|
|
||||||
while has_more:
|
while has_more:
|
||||||
if cursor:
|
try:
|
||||||
search_params["start_cursor"] = cursor
|
if cursor:
|
||||||
|
search_params["start_cursor"] = cursor
|
||||||
|
|
||||||
# Use retry wrapper for search API call
|
# Use retry wrapper for search API call
|
||||||
search_results = await self._api_call_with_retry(
|
search_results = await self._api_call_with_retry(
|
||||||
notion.search, on_retry=self._on_retry_callback, **search_params
|
notion.search, on_retry=self._on_retry_callback, **search_params
|
||||||
)
|
)
|
||||||
|
|
||||||
pages.extend(search_results["results"])
|
pages.extend(search_results["results"])
|
||||||
has_more = search_results.get("has_more", False)
|
has_more = search_results.get("has_more", False)
|
||||||
|
|
||||||
if has_more:
|
if has_more:
|
||||||
cursor = search_results.get("next_cursor")
|
cursor = search_results.get("next_cursor")
|
||||||
|
|
||||||
|
except APIResponseError as e:
|
||||||
|
error_message = str(e)
|
||||||
|
# Handle invalid cursor - stop pagination gracefully
|
||||||
|
if "start_cursor provided is invalid" in error_message:
|
||||||
|
logger.warning(
|
||||||
|
f"Invalid pagination cursor encountered. "
|
||||||
|
f"Continuing with {len(pages)} pages already fetched."
|
||||||
|
)
|
||||||
|
has_more = False
|
||||||
|
continue
|
||||||
|
# Re-raise other errors
|
||||||
|
raise
|
||||||
|
|
||||||
all_page_data = []
|
all_page_data = []
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue