append the error in the internal server error

undo the linter changes

catch the assert error and report to the client

fix linter issue

convert asserts to raise exception for better error hanlding

translate assert to exception accordingly
This commit is contained in:
Henry Tai 2024-11-21 03:48:39 +08:00
parent 1619d37cc6
commit 663f222ffd
2 changed files with 19 additions and 8 deletions

View file

@ -97,6 +97,10 @@ def translate_exception(exc: Exception) -> Union[HTTPException, RequestValidatio
)
elif isinstance(exc, ValueError):
return HTTPException(status_code=400, detail=f"Invalid value: {str(exc)}")
elif isinstance(exc, TypeError):
return HTTPException(status_code=400, detail=f"Type Error: {str(exc)}")
elif isinstance(exc, KeyError):
return HTTPException(status_code=400, detail=f"Key Error: {str(exc)}")
elif isinstance(exc, PermissionError):
return HTTPException(status_code=403, detail=f"Permission denied: {str(exc)}")
elif isinstance(exc, TimeoutError):