Skip to content

Commit

Permalink
fix: Handle prompt too big error (#401)
Browse files Browse the repository at this point in the history
  • Loading branch information
whiterabbit1983 committed Jun 25, 2024
1 parent 3472df2 commit e8090dd
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion agents-api/agents_api/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from fastapi.middleware.cors import CORSMiddleware
from fastapi.exceptions import RequestValidationError
from agents_api.common.exceptions import BaseCommonException
from agents_api.exceptions import PromptTooBigError
from pycozo.client import QueryException
from temporalio.service import RPCError

Expand Down Expand Up @@ -96,7 +97,7 @@ def register_exceptions(app: FastAPI):
@app.exception_handler(RPCError)
async def validation_error_handler(request: Request, exc: RPCError):
return JSONResponse(
status_code=400,
status_code=status.HTTP_400_BAD_REQUEST,
content={
"error": {"message": "job not found or invalid", "code": exc.status.name}
},
Expand All @@ -111,6 +112,14 @@ async def session_not_found_error_handler(request: Request, exc: BaseCommonExcep
)


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


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

0 comments on commit e8090dd

Please sign in to comment.