Skip to content

Commit f2eeccb

Browse files
committed
fixes http response headers
1 parent 86f90a2 commit f2eeccb

File tree

3 files changed

+11
-15
lines changed

3 files changed

+11
-15
lines changed

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from models_library.api_schemas_webserver.activity import ActivityStatusDict
77
from pydantic import TypeAdapter
88
from servicelib.aiohttp.client_session import get_client_session
9+
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
910
from servicelib.request_keys import RQT_USERID_KEY
1011
from yarl import URL
1112

services/web/server/src/simcore_service_webserver/exception_handling/_factory.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
from common_library.error_codes import create_error_code
66
from common_library.json_serialization import json_dumps
77
from models_library.rest_error import ErrorGet
8+
from servicelib.aiohttp.rest_responses import safe_status_message
89
from servicelib.aiohttp.web_exceptions_extension import get_all_aiohttp_http_exceptions
910
from servicelib.logging_errors import create_troubleshootting_log_kwargs
1011
from servicelib.status_codes_utils import (
11-
get_code_description,
12+
get_code_display_name,
1213
is_5xx_server_error,
1314
is_error,
1415
)
@@ -53,7 +54,7 @@ def create_error_response(error: ErrorGet, status_code: int) -> web.Response:
5354
return web.json_response(
5455
data={"error": error.model_dump(exclude_unset=True, mode="json")},
5556
dumps=json_dumps,
56-
reason=get_code_description(status_code),
57+
reason=safe_status_message(get_code_display_name(status_code)),
5758
status=status_code,
5859
)
5960

services/web/server/tests/unit/isolated/test_exception_handling_factory.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from aiohttp.test_utils import make_mocked_request
1414
from servicelib.aiohttp import status
1515
from servicelib.mimetype_constants import MIMETYPE_APPLICATION_JSON
16+
from servicelib.status_codes_utils import get_code_display_name
1617
from simcore_service_webserver.errors import WebServerBaseError
1718
from simcore_service_webserver.exception_handling._base import (
1819
ExceptionHandlingContextManager,
@@ -28,16 +29,13 @@
2829
# Some custom errors in my service
2930

3031

31-
class BaseError(WebServerBaseError):
32-
...
32+
class BaseError(WebServerBaseError): ...
3333

3434

35-
class OneError(BaseError):
36-
...
35+
class OneError(BaseError): ...
3736

3837

39-
class OtherError(BaseError):
40-
...
38+
class OtherError(BaseError): ...
4139

4240

4341
@pytest.fixture
@@ -58,7 +56,7 @@ async def test_factory__create_exception_handler_from_http_error(
5856
response = await one_error_to_404(fake_request, caught)
5957
assert response.status == status.HTTP_404_NOT_FOUND
6058
assert response.text is not None
61-
assert "one error message" in response.reason
59+
assert response.reason == get_code_display_name(response.status)
6260
assert response.content_type == MIMETYPE_APPLICATION_JSON
6361

6462

@@ -82,9 +80,7 @@ async def test_handling_different_exceptions_with_context(
8280
response = cm.get_response_or_none()
8381
assert response is not None
8482
assert response.status == status.HTTP_400_BAD_REQUEST
85-
assert response.reason == exc_to_http_error_map[OneError].msg_template.format(
86-
code="WebServerBaseError.BaseError.OneError"
87-
)
83+
assert response.reason == get_code_display_name(response.status)
8884
assert not caplog.records
8985

9086
# unhandled -> reraises
@@ -103,9 +99,7 @@ async def test_handling_different_exceptions_with_context(
10399
response = cm.get_response_or_none()
104100
assert response is not None
105101
assert response.status == status.HTTP_500_INTERNAL_SERVER_ERROR
106-
assert response.reason == exc_to_http_error_map[OtherError].msg_template.format(
107-
code="WebServerBaseError.BaseError.OtherError"
108-
)
102+
assert response.reason == get_code_display_name(response.status)
109103
assert caplog.records, "Expected 5XX troubleshooting logged as error"
110104
assert caplog.records[0].levelno == logging.ERROR
111105

0 commit comments

Comments
 (0)