Skip to content

Commit 1d8ff13

Browse files
committed
fix type error
1 parent 91702f0 commit 1d8ff13

File tree

1 file changed

+10
-10
lines changed

1 file changed

+10
-10
lines changed

api/birdxplorer_api/routers/data.py

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from datetime import timezone
22
from typing import List, TypeAlias, Union
3+
from urllib.parse import urlencode
34

45
from dateutil.parser import parse as dateutil_parse
56
from fastapi import APIRouter, HTTPException, Path, Query, Request
@@ -31,7 +32,6 @@
3132
UserId,
3233
)
3334
from birdxplorer_common.storage import Storage
34-
from urllib.parse import urlencode
3535

3636
PostsPaginationMetaWithExamples: TypeAlias = Annotated[
3737
PaginationMeta,
@@ -279,8 +279,8 @@ def ensure_twitter_timestamp(t: Union[str, TwitterTimestamp]) -> TwitterTimestam
279279
try:
280280
timestamp = str_to_twitter_timestamp(t) if isinstance(t, str) else t
281281
return timestamp
282-
except:
283-
raise ValueError(f"Timestamp out of range")
282+
except OverflowError:
283+
raise OverflowError("Timestamp out of range")
284284

285285

286286
def gen_router(storage: Storage) -> APIRouter:
@@ -324,7 +324,7 @@ def get_notes(
324324
created_at_from = ensure_twitter_timestamp(created_at_from)
325325
if created_at_to is not None and isinstance(created_at_to, str):
326326
created_at_to = ensure_twitter_timestamp(created_at_to)
327-
except ValueError as e:
327+
except OverflowError as e:
328328
raise HTTPException(status_code=422, detail=str(e))
329329

330330
notes = list(
@@ -387,7 +387,7 @@ def get_posts(
387387
created_at_from = ensure_twitter_timestamp(created_at_from)
388388
if created_at_to is not None and isinstance(created_at_to, str):
389389
created_at_to = ensure_twitter_timestamp(created_at_to)
390-
except ValueError as e:
390+
except OverflowError as e:
391391
raise HTTPException(status_code=422, detail=str(e))
392392

393393
posts = list(
@@ -467,7 +467,7 @@ def search(
467467
note_created_at_from = ensure_twitter_timestamp(note_created_at_from)
468468
if note_created_at_to is not None and isinstance(note_created_at_to, str):
469469
note_created_at_to = ensure_twitter_timestamp(note_created_at_to)
470-
except ValueError as e:
470+
except OverflowError as e:
471471
raise HTTPException(status_code=422, detail=str(e))
472472

473473
# Get search results using the optimized storage method
@@ -533,14 +533,14 @@ def search(
533533

534534
next_url = None
535535
if next_offset < total_count:
536-
query_params["offset"] = next_offset
537-
query_params["limit"] = limit
536+
query_params["offset"] = str(next_offset)
537+
query_params["limit"] = str(limit)
538538
next_url = f"{base_url}?{urlencode(query_params)}"
539539

540540
prev_url = None
541541
if offset > 0:
542-
query_params["offset"] = prev_offset
543-
query_params["limit"] = limit
542+
query_params["offset"] = str(prev_offset)
543+
query_params["limit"] = str(limit)
544544
prev_url = f"{base_url}?{urlencode(query_params)}"
545545

546546
return SearchResponse(data=results, meta=PaginationMeta(next=next_url, prev=prev_url))

0 commit comments

Comments
 (0)