Skip to content
This repository has been archived by the owner on Mar 1, 2024. It is now read-only.

Commit

Permalink
shu/fix wyvern error handling (#83)
Browse files Browse the repository at this point in the history
* move error handling to fastapi framework

* v0.0.26

* add wyvern error warning

* handle WyvernError in except handler
  • Loading branch information
wintonzheng authored Oct 6, 2023
1 parent ec17d53 commit 99571b8
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[tool.poetry]
name = "wyvern-ai"
version = "0.0.25"
version = "0.0.26"
description = ""
authors = ["Wyvern AI <info@wyvern.ai>"]
readme = "README.md"
Expand Down
19 changes: 9 additions & 10 deletions wyvern/web_frameworks/fastapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"}
Expand Down Expand Up @@ -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))
Expand Down

0 comments on commit 99571b8

Please sign in to comment.