Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[IMP] fastapi: detail to have ValueError exception message #472

Open
wants to merge 1 commit into
base: 17.0
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The version will be changed at merge time. Can you remove this change plz.

"license": "LGPL-3",
"author": "ACSONE SA/NV,Odoo Community Association (OCA)",
"maintainers": ["lmignon"],
Expand Down
6 changes: 6 additions & 0 deletions fastapi/error_handlers.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright 2022 ACSONE SA/NV
# License LGPL-3.0 or later (http://www.gnu.org/licenses/LGPL).

import traceback

from starlette import status
from starlette.exceptions import HTTPException, WebSocketException
from starlette.middleware.errors import ServerErrorMiddleware
Expand All @@ -10,6 +12,7 @@
from werkzeug.exceptions import HTTPException as WerkzeugHTTPException

from odoo.exceptions import AccessDenied, AccessError, MissingError, UserError
from odoo.tools import config

from fastapi import Request
from fastapi.encoders import jsonable_encoder
Expand All @@ -21,6 +24,9 @@
body = {}
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
details = "Internal Server Error"
if config.get_misc("fastapi", "dev_mode"):
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This config should be added into the documentation in a readme/CONFIGURE.rst (ex https://github.com/OCA/rest-framework/blob/16.0/base_rest/readme/CONFIGURE.rst)

tb = "".join(traceback.format_exception(exc))
details = f"{details}\n{tb}"

Check warning on line 29 in fastapi/error_handlers.py

View check run for this annotation

Codecov / codecov/patch

fastapi/error_handlers.py#L28-L29

Added lines #L28 - L29 were not covered by tests

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