From 475fd139777b0e760fe2ddd89a706d2d27c07295 Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 8 Oct 2024 19:34:51 +0200 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20Fixes=20bad=20formatting=20while?= =?UTF-8?q?=20handling=20missing=20configuration=20errors=20(#6501)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/servicelib/aiohttp/rest_middlewares.py | 10 ++++++++-- .../tests/aiohttp/test_rest_middlewares.py | 7 +++++-- .../src/simcore_service_webserver/users/_handlers.py | 2 +- .../web/server/tests/unit/with_dbs/03/test_users.py | 4 +++- 4 files changed, 17 insertions(+), 6 deletions(-) diff --git a/packages/service-library/src/servicelib/aiohttp/rest_middlewares.py b/packages/service-library/src/servicelib/aiohttp/rest_middlewares.py index bc6b6354031..0b6af4a5428 100644 --- a/packages/service-library/src/servicelib/aiohttp/rest_middlewares.py +++ b/packages/service-library/src/servicelib/aiohttp/rest_middlewares.py @@ -31,7 +31,11 @@ from .typing_extension import Handler, Middleware DEFAULT_API_VERSION = "v0" -FMSG_INTERNAL_ERROR_USER_FRIENDLY = "We apologize for the inconvenience. Our team has recorded the issue and is working to resolve it as quickly as possible. Thank you for your patience [{}]" +_FMSG_INTERNAL_ERROR_USER_FRIENDLY_WITH_OEC = ( + "We apologize for the inconvenience." + " Our team has recorded the issue [{error_code}] and is working to resolve it as quickly as possible." + " Thank you for your patience" +) _logger = logging.getLogger(__name__) @@ -58,7 +62,9 @@ def _process_and_raise_unexpected_error(request: web.BaseRequest, err: Exception if isinstance(err, OsparcErrorMixin): error_context.update(err.error_context()) - frontend_msg = FMSG_INTERNAL_ERROR_USER_FRIENDLY.format(error_code) + frontend_msg = _FMSG_INTERNAL_ERROR_USER_FRIENDLY_WITH_OEC.format( + error_code=error_code + ) log_msg = create_troubleshotting_log_message( message_to_user=frontend_msg, error=err, diff --git a/packages/service-library/tests/aiohttp/test_rest_middlewares.py b/packages/service-library/tests/aiohttp/test_rest_middlewares.py index 1cad85a2e61..e70b6963b43 100644 --- a/packages/service-library/tests/aiohttp/test_rest_middlewares.py +++ b/packages/service-library/tests/aiohttp/test_rest_middlewares.py @@ -16,7 +16,7 @@ from models_library.utils.json_serialization import json_dumps from servicelib.aiohttp import status from servicelib.aiohttp.rest_middlewares import ( - FMSG_INTERNAL_ERROR_USER_FRIENDLY, + _FMSG_INTERNAL_ERROR_USER_FRIENDLY_WITH_OEC, envelope_middleware_factory, error_middleware_factory, ) @@ -238,7 +238,10 @@ async def test_raised_unhandled_exception( # user friendly message with OEC reference assert "OEC" in error["message"] parsed_oec = parse_error_code(error["message"]).pop() - assert FMSG_INTERNAL_ERROR_USER_FRIENDLY.format(parsed_oec) == error["message"] + assert ( + _FMSG_INTERNAL_ERROR_USER_FRIENDLY_WITH_OEC.format(error_code=parsed_oec) + == error["message"] + ) # avoids details assert not error.get("errors") diff --git a/services/web/server/src/simcore_service_webserver/users/_handlers.py b/services/web/server/src/simcore_service_webserver/users/_handlers.py index ba8e1053016..a8516095e57 100644 --- a/services/web/server/src/simcore_service_webserver/users/_handlers.py +++ b/services/web/server/src/simcore_service_webserver/users/_handlers.py @@ -54,7 +54,7 @@ async def wrapper(request: web.Request) -> web.StreamResponse: raise web.HTTPNotFound(reason=f"{exc}") from exc except MissingGroupExtraPropertiesForProductError as exc: error_code = create_error_code(exc) - frontend_msg = FMSG_MISSING_CONFIG_WITH_OEC.format(error_code) + frontend_msg = FMSG_MISSING_CONFIG_WITH_OEC.format(error_code=error_code) log_msg = create_troubleshotting_log_message( message_to_user=frontend_msg, error=exc, diff --git a/services/web/server/tests/unit/with_dbs/03/test_users.py b/services/web/server/tests/unit/with_dbs/03/test_users.py index dac6f6696c4..80c0c7912af 100644 --- a/services/web/server/tests/unit/with_dbs/03/test_users.py +++ b/services/web/server/tests/unit/with_dbs/03/test_users.py @@ -196,7 +196,9 @@ async def test_get_profile_with_failing_db_connection( resp = await client.get(url.path) - await assert_status(resp, expected) + data, error = await assert_status(resp, expected) + assert not data + assert error["message"] == "Authentication service is temporary unavailable" @pytest.mark.parametrize(