From a76701751d5daac89f76f4511f8d2e823571d7ab Mon Sep 17 00:00:00 2001 From: Pedro Crespo-Valero <32402063+pcrespov@users.noreply.github.com> Date: Tue, 24 Sep 2024 14:25:59 +0200 Subject: [PATCH] user error and log --- .../simcore_service_webserver/_constants.py | 13 ++++++++++ .../users/_constants.py | 7 ++++++ .../users/_handlers.py | 24 +++++++++++++++++-- 3 files changed, 42 insertions(+), 2 deletions(-) create mode 100644 services/web/server/src/simcore_service_webserver/users/_constants.py diff --git a/services/web/server/src/simcore_service_webserver/_constants.py b/services/web/server/src/simcore_service_webserver/_constants.py index 91b70f453074..10033b67306c 100644 --- a/services/web/server/src/simcore_service_webserver/_constants.py +++ b/services/web/server/src/simcore_service_webserver/_constants.py @@ -28,6 +28,19 @@ ] = "Under development. Use WEBSERVER_DEV_FEATURES_ENABLED=1 to enable current implementation" +FMSG_SERVER_EXCEPTION_LOG: Final[ + # formatted message for _logger.exception(...) + # Use these keys as guidance to provide necessary information for a good error message log + # + # user_msg: message seem by front-end user (should include OEC) + # exc: handled exception + # ctx: exception context e.g. exc.ctx() (see OsparcErrorMixin) + # tip: tips on why this might have happened and or possible solution + # + str +] = "{user_msg}.\nERROR: {exc}.\nCONTEXT: {ctx}.\nTIP: {tip}\n" + + __all__: tuple[str, ...] = ( "APP_CONFIG_KEY", "APP_DB_ENGINE_KEY", diff --git a/services/web/server/src/simcore_service_webserver/users/_constants.py b/services/web/server/src/simcore_service_webserver/users/_constants.py new file mode 100644 index 000000000000..5347d3e7527f --- /dev/null +++ b/services/web/server/src/simcore_service_webserver/users/_constants.py @@ -0,0 +1,7 @@ +from typing import Final + +FMSG_MISSING_CONFIG_WITH_OEC: Final[str] = ( + "The product is not ready for use until the configuration is fully completed. " + "Please wait and try again. " + "If the issue continues, contact support with error code: {error_code}." +) 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 ede00340d4e1..e4cb8031fab3 100644 --- a/services/web/server/src/simcore_service_webserver/users/_handlers.py +++ b/services/web/server/src/simcore_service_webserver/users/_handlers.py @@ -9,18 +9,24 @@ parse_request_query_parameters_as, ) from servicelib.aiohttp.typing_extension import Handler +from servicelib.error_codes import create_error_code from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON from servicelib.request_keys import RQT_USERID_KEY from servicelib.rest_constants import RESPONSE_MODEL_POLICY -from .._constants import RQ_PRODUCT_KEY +from .._constants import FMSG_SERVER_EXCEPTION_LOG, RQ_PRODUCT_KEY from .._meta import API_VTAG from ..login.decorators import login_required from ..security.decorators import permission_required from ..utils_aiohttp import envelope_json_response from . import _api, api +from ._constants import FMSG_MISSING_CONFIG_WITH_OEC from ._schemas import PreUserProfile -from .exceptions import AlreadyPreRegisteredError, UserNotFoundError +from .exceptions import ( + AlreadyPreRegisteredError, + MissingGroupExtraPropertiesForProductError, + UserNotFoundError, +) from .schemas import ProfileGet, ProfileUpdate _logger = logging.getLogger(__name__) @@ -42,6 +48,20 @@ async def wrapper(request: web.Request) -> web.StreamResponse: except UserNotFoundError as exc: raise web.HTTPNotFound(reason=f"{exc}") from exc + except MissingGroupExtraPropertiesForProductError as exc: + error_code = create_error_code(exc) + user_msg = FMSG_MISSING_CONFIG_WITH_OEC.format(error_code) + log_msg = FMSG_SERVER_EXCEPTION_LOG.format( + user_msg=user_msg, + exc=exc, + ctx=exc.ctx(), + tip="Row in `groups_extra_properties` for this product is missing.", + ) + _logger.exception( + log_msg, + extra={"error_code": error_code}, + ) + raise web.HTTPServiceUnavailable(reason=user_msg) from exc return wrapper