diff --git a/swh/storage/cassandra/storage.py b/swh/storage/cassandra/storage.py --- a/swh/storage/cassandra/storage.py +++ b/swh/storage/cassandra/storage.py @@ -1318,7 +1318,12 @@ next_page_token = None date_from = None if page_token is not None: - date_from = datetime.datetime.fromisoformat(page_token) + try: + date_from = datetime.datetime.fromisoformat(page_token) + except ValueError: + raise StorageArgumentException( + "Invalid page_token argument to origin_visit_status_get." + ) from None # Take one more visit status so we can reuse it as the next page token if any rows = self._cql_runner.origin_visit_status_get_range( diff --git a/swh/storage/postgresql/storage.py b/swh/storage/postgresql/storage.py --- a/swh/storage/postgresql/storage.py +++ b/swh/storage/postgresql/storage.py @@ -1314,7 +1314,12 @@ next_page_token = None date_from = None if page_token is not None: - date_from = datetime.datetime.fromisoformat(page_token) + try: + date_from = datetime.datetime.fromisoformat(page_token) + except ValueError: + raise StorageArgumentException( + "Invalid page_token argument to origin_visit_status_get." + ) from None visit_statuses: List[OriginVisitStatus] = [] # Take one more visit status so we can reuse it as the next page token if any