Skip to content

Commit 09fd1b2

Browse files
committed
added bug fix for small edge case on fast_api error message
added many more tests to test_Fast_API (increased code coverage from 80% to 90%
1 parent fedaee3 commit 09fd1b2

3 files changed

Lines changed: 572 additions & 12 deletions

File tree

osbot_fast_api/api/Fast_API.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
from osbot_utils.type_safe.primitives.domains.common.safe_str.Safe_Str__Text import Safe_Str__Text
55
from osbot_utils.type_safe.primitives.domains.common.safe_str.Safe_Str__Version import Safe_Str__Version
66
from osbot_utils.type_safe.primitives.domains.identifiers.Random_Guid import Random_Guid
7+
from osbot_utils.utils.Json import json_loads, json_dumps
78
from starlette.staticfiles import StaticFiles
89
from osbot_fast_api.admin_ui.api.Admin_UI__Config import Admin_UI__Config
910
from osbot_fast_api.api.Fast_API__Offline_Docs import Fast_API__Offline_Docs, FILE_PATH__STATIC__DOCS, URL__STATIC__DOCS, NAME__STATIC__DOCS
@@ -58,7 +59,8 @@ async def http_exception_handler(request: Request, exc: HTTPException):
5859

5960
@app.exception_handler(RequestValidationError)
6061
async def validation_exception_handler(request: Request, exc: RequestValidationError):
61-
return JSONResponse( status_code=400, content={"detail": exc.errors()} )
62+
errors_dict = json_loads(json_dumps(exc.errors(), pretty=False)) # need this round trip to handle the case when exception has non json parseable content (like bytes)
63+
return JSONResponse( status_code=400, content={"detail": errors_dict })
6264

6365

6466
def add_flask_app(self, path, flask_app):

0 commit comments

Comments
 (0)