Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🐛 Fixes bad formatting while handling missing configuration errors #6501

Merged
merged 6 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading