Skip to content

Commit

Permalink
Return Response with status_code=500 if error
Browse files Browse the repository at this point in the history
  • Loading branch information
deedy5 committed Mar 18, 2024
1 parent 638eac3 commit 62f284c
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions duckduckgo_search_api/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@

import uvicorn
from duckduckgo_search import AsyncDDGS
from litestar import Litestar, get
from litestar import Litestar, Response, get
from litestar.config.app import ExperimentalFeatures
from litestar.config.compression import CompressionConfig
from litestar.openapi import OpenAPIConfig, OpenAPIController
from litestar.params import Parameter
from litestar.status_codes import HTTP_500_INTERNAL_SERVER_ERROR

__version__ = "0.8.0"

Expand Down Expand Up @@ -61,7 +62,7 @@ class DdgNewsOut:
image: str


class MyOpenAPIController(OpenAPIController):
class MyOpenAPIController(OpenAPIController): ## type: ignore
path = "/"


Expand Down Expand Up @@ -104,7 +105,7 @@ async def ddg_text_search(
return cast(list[DdgTextOut], results)
except Exception as ex:
logging.warning(ex)
return []
return Response(status_code=HTTP_500_INTERNAL_SERVER_ERROR) # type: ignore


@get("/images") ## type: ignore
Expand Down Expand Up @@ -181,7 +182,7 @@ async def ddg_images_search(
return cast(list[DdgImagesOut], results)
except Exception as ex:
logging.warning(ex)
return []
return Response(status_code=HTTP_500_INTERNAL_SERVER_ERROR) # type: ignore


@get("/videos") ## type: ignore
Expand Down Expand Up @@ -233,7 +234,7 @@ async def ddg_videos_search(
return cast(list[DdgVideosOut], results)
except Exception as ex:
logging.warning(ex)
return []
return Response(status_code=HTTP_500_INTERNAL_SERVER_ERROR) # type: ignore


@get("/news") ## type: ignore
Expand Down Expand Up @@ -270,7 +271,7 @@ async def ddg_news_search(
return cast(list[DdgNewsOut], results)
except Exception as ex:
logging.warning(ex)
return []
return Response(status_code=HTTP_500_INTERNAL_SERVER_ERROR) # type: ignore


app = Litestar(
Expand Down

0 comments on commit 62f284c

Please sign in to comment.