Skip to content

Commit

Permalink
user error and log
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov committed Sep 24, 2024
1 parent 5f26f6f commit a767017
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 2 deletions.
13 changes: 13 additions & 0 deletions services/web/server/src/simcore_service_webserver/_constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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}."
)
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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

Expand Down

0 comments on commit a767017

Please sign in to comment.