Skip to content

Commit 4b25dcf

Browse files
committed
user error and log
1 parent 4927ebe commit 4b25dcf

File tree

3 files changed

+42
-2
lines changed

3 files changed

+42
-2
lines changed

services/web/server/src/simcore_service_webserver/_constants.py

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,19 @@
2828
] = "Under development. Use WEBSERVER_DEV_FEATURES_ENABLED=1 to enable current implementation"
2929

3030

31+
FMSG_SERVER_EXCEPTION_LOG: Final[
32+
# formatted message for _logger.exception(...)
33+
# Use these keys as guidance to provide necessary information for a good error message log
34+
#
35+
# user_msg: message seem by front-end user (should include OEC)
36+
# exc: handled exception
37+
# ctx: exception context e.g. exc.ctx() (see OsparcErrorMixin)
38+
# tip: tips on why this might have happened and or possible solution
39+
#
40+
str
41+
] = "{user_msg}.\nERROR: {exc}.\nCONTEXT: {ctx}.\nTIP: {tip}\n"
42+
43+
3144
__all__: tuple[str, ...] = (
3245
"APP_CONFIG_KEY",
3346
"APP_DB_ENGINE_KEY",
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
from typing import Final
2+
3+
FMSG_MISSING_CONFIG_WITH_OEC: Final[str] = (
4+
"The product is not ready for use until the configuration is fully completed. "
5+
"Please wait and try again. "
6+
"If the issue continues, contact support with error code: {error_code}."
7+
)

services/web/server/src/simcore_service_webserver/users/_handlers.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,24 @@
99
parse_request_query_parameters_as,
1010
)
1111
from servicelib.aiohttp.typing_extension import Handler
12+
from servicelib.error_codes import create_error_code
1213
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
1314
from servicelib.request_keys import RQT_USERID_KEY
1415
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
1516

16-
from .._constants import RQ_PRODUCT_KEY
17+
from .._constants import FMSG_SERVER_EXCEPTION_LOG, RQ_PRODUCT_KEY
1718
from .._meta import API_VTAG
1819
from ..login.decorators import login_required
1920
from ..security.decorators import permission_required
2021
from ..utils_aiohttp import envelope_json_response
2122
from . import _api, api
23+
from ._constants import FMSG_MISSING_CONFIG_WITH_OEC
2224
from ._schemas import PreUserProfile
23-
from .exceptions import AlreadyPreRegisteredError, UserNotFoundError
25+
from .exceptions import (
26+
AlreadyPreRegisteredError,
27+
MissingGroupExtraPropertiesForProductError,
28+
UserNotFoundError,
29+
)
2430
from .schemas import ProfileGet, ProfileUpdate
2531

2632
_logger = logging.getLogger(__name__)
@@ -42,6 +48,20 @@ async def wrapper(request: web.Request) -> web.StreamResponse:
4248

4349
except UserNotFoundError as exc:
4450
raise web.HTTPNotFound(reason=f"{exc}") from exc
51+
except MissingGroupExtraPropertiesForProductError as exc:
52+
error_code = create_error_code(exc)
53+
user_msg = FMSG_MISSING_CONFIG_WITH_OEC.format(error_code)
54+
log_msg = FMSG_SERVER_EXCEPTION_LOG.format(
55+
user_msg=user_msg,
56+
exc=exc,
57+
ctx=exc.ctx(),
58+
tip="Row in `groups_extra_properties` for this product is missing.",
59+
)
60+
_logger.exception(
61+
log_msg,
62+
extra={"error_code": error_code},
63+
)
64+
raise web.HTTPServiceUnavailable(reason=user_msg) from exc
4565

4666
return wrapper
4767

0 commit comments

Comments
 (0)