From 84e07e87f4b15bad85525899f7bcae3547938517 Mon Sep 17 00:00:00 2001 From: "Laurent Mignon (ACSONE)" Date: Thu, 14 Mar 2024 16:11:48 +0100 Subject: [PATCH] [FIX] fastapi: Handle error occurring outside the fastapi processing To ensure that exception orrurring outside of the fastapi processing stack are properly handled, implement the 'handle_error' method into the FastApiDispatcher class --- fastapi/fastapi_dispatcher.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fastapi/fastapi_dispatcher.py b/fastapi/fastapi_dispatcher.py index 02738b9b..41587a73 100644 --- a/fastapi/fastapi_dispatcher.py +++ b/fastapi/fastapi_dispatcher.py @@ -4,6 +4,8 @@ from contextlib import contextmanager from io import BytesIO +from werkzeug.exceptions import InternalServerError + from odoo.http import Dispatcher, request from .context import odoo_env_ctx @@ -35,7 +37,10 @@ def dispatch(self, endpoint, args): ) def handle_error(self, exc): - pass + # At this stage all the normal exceptions are handled by FastAPI + # and we should only have InternalServerError occurring after the + # FastAPI app has been called. + return InternalServerError() # pragma: no cover def _make_response(self, status_mapping, headers_tuple, content): self.status = status_mapping[:3]