Skip to content

Commit

Permalink
[IMP] fastapi: detail to have exception message if debug flag provided
Browse files Browse the repository at this point in the history
  • Loading branch information
viktor-anikeenko-avsys committed Nov 12, 2024
1 parent f89d54d commit 26de529
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
2 changes: 1 addition & 1 deletion fastapi/__manifest__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"name": "Odoo FastAPI",
"summary": """
Odoo FastAPI endpoint""",
"version": "17.0.3.0.1",
"version": "17.0.4.0.0",
"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["lmignon"],
Expand Down
6 changes: 5 additions & 1 deletion fastapi/error_handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Copyright 2022 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).

import os
from starlette import status
from starlette.exceptions import HTTPException, WebSocketException
from starlette.middleware.errors import ServerErrorMiddleware
Expand All @@ -20,7 +21,10 @@
def convert_exception_to_status_body(exc: Exception) -> tuple[int, dict]:
body = {}
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
details = "Internal Server Error"
if os.getenv("FASTAPI_DEBUG") == "1":
details = repr(exc)
else:
details = "Internal Server Error"

if isinstance(exc, WerkzeugHTTPException):
status_code = exc.code
Expand Down

0 comments on commit 26de529

Please sign in to comment.