diff --git a/agents-api/agents_api/web.py b/agents-api/agents_api/web.py index b44e94a0e..28980eb26 100644 --- a/agents-api/agents_api/web.py +++ b/agents-api/agents_api/web.py @@ -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 @@ -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} }, @@ -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,