Skip to content

Commit

Permalink
🐛 Fixes bad formatting while handling missing configuration errors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pcrespov authored Oct 8, 2024
1 parent 997eeb3 commit 54f9bcd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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__)
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
)
Expand Down Expand Up @@ -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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 3 additions & 1 deletion services/web/server/tests/unit/with_dbs/03/test_users.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down

0 comments on commit 54f9bcd

Please sign in to comment.