added exception handling

This commit is contained in:
Kazgatari
2026-07-31 16:04:14 +02:00
parent 9c3e36930c
commit faa866f4e1
2 changed files with 15 additions and 18 deletions
@@ -3,6 +3,7 @@ from typing import List, Optional
from fastapi import APIRouter, Query, Depends
from inse.tags import Tags
from inse.exceptions import BadRequestException
from . import logic, trend_logic
from .model import (
RankingResponse,
@@ -43,7 +44,7 @@ def get_trend_strategy(search_type: TrendSearchType = Query(TrendSearchType.PUBL
return NewsTrendStrategy()
elif search_type == TrendSearchType.ALL:
return AllTrendStrategy()
raise ValueError(f"Unknown search type: {search_type}")
raise BadRequestException(f"Unknown search type: {search_type}")
@router.get(
"",
@@ -74,6 +75,8 @@ async def get_trend(
authors: Optional[List[str]] = Query(None, description="List of OpenAlex Author IDs"),
strategy: TrendStrategy = Depends(get_trend_strategy)
):
if not topics or len(topics) == 0:
raise BadRequestException("Topics list cannot be empty")
return await strategy.get_trend(
topics=topics,
keywords=keywords,