added exception handling
This commit is contained in:
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user