Skip to content

Commit

Permalink
fix: Add exception handler for litellm API error (#432)
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 authored Jul 12, 2024
1 parent 83046fa commit c703332
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from agents_api.exceptions import PromptTooBigError
from pycozo.client import QueryException
from temporalio.service import RPCError
from litellm.exceptions import APIError

from agents_api.dependencies.auth import get_api_key
from agents_api.env import sentry_dsn
Expand Down Expand Up @@ -120,6 +121,14 @@ async def prompt_too_big_error(request: Request, exc: PromptTooBigError):
)


@app.exception_handler(APIError)
async def litellm_api_error(request: Request, exc: APIError):
return JSONResponse(
status_code=status.HTTP_502_BAD_GATEWAY,
content={"error": {"message": str(exc)}},
)


def main(
host="127.0.0.1",
port=8000,
Expand Down

0 comments on commit c703332

Please sign in to comment.