diff --git a/pyproject.toml b/pyproject.toml index 55a3f9f..4a7af71 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,6 +1,6 @@ [tool.poetry] name = "wyvern-ai" -version = "0.0.25" +version = "0.0.26" description = "" authors = ["Wyvern AI "] readme = "README.md" diff --git a/wyvern/web_frameworks/fastapi.py b/wyvern/web_frameworks/fastapi.py index 07b4084..baba3d3 100644 --- a/wyvern/web_frameworks/fastapi.py +++ b/wyvern/web_frameworks/fastapi.py @@ -72,16 +72,6 @@ def __init__(self, host: str = "127.0.0.1", port: int = 8000) -> None: self.host = host self.port = port - @self.app.exception_handler(WyvernError) - async def wyvern_exception_handler(request: Request, exc: WyvernError): - return JSONResponse( - status_code=400, - content={ - "detail": str(exc), - "error_code": exc.error_code, - }, - ) - @self.app.get("/healthcheck") async def healthcheck() -> Dict[str, str]: return {"status": "OK"} @@ -181,6 +171,15 @@ async def post( except ValidationError as e: logger.exception(f"Validation error error={e} request_payload={json}") raise HTTPException(status_code=422, detail=e.errors()) + except WyvernError as e: + logger.warning(f"Wyvern error error={e} request_payload={json}") + return JSONResponse( + status_code=400, + content={ + "detail": str(e), + "error_code": e.error_code, + }, + ) except Exception as e: logger.exception(f"Unexpected error error={e} request_payload={json}") raise HTTPException(status_code=500, detail=str(e))