-
Notifications
You must be signed in to change notification settings - Fork 32
🎨♻️ Enhances web-server's error middle-ware for safe status-line and refactors aiohttp response helpers #7770
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
🎨♻️ Enhances web-server's error middle-ware for safe status-line and refactors aiohttp response helpers #7770
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## master #7770 +/- ##
==========================================
- Coverage 86.75% 86.43% -0.32%
==========================================
Files 1850 1435 -415
Lines 71889 60151 -11738
Branches 1216 617 -599
==========================================
- Hits 62365 51993 -10372
+ Misses 9183 7959 -1224
+ Partials 341 199 -142
Continue to review full report in Codecov by Sentry.
🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR refactors response helpers in the servicelib.aiohttp package to introduce a safe status-line sanitizer, simplify data responses, and update related tests and middleware.
- Adds
safe_status_messageto truncate and clean HTTP reason phrases - Simplifies
create_data_responseand removes legacy error-handling paths - Updates tests and director_v2 exception handler to use the new
status_reasonparameter
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py | Switched from reason= to status_reason= in create_http_error. |
| packages/service-library/src/servicelib/aiohttp/rest_responses.py | Refactored data responses, added safe_status_message, removed dead code. |
| packages/service-library/src/servicelib/aiohttp/rest_middlewares.py | Applied safe_status_message to middleware and simplified response flow. |
| packages/service-library/tests/aiohttp/test_rest_responses.py | Updated tests to cover error_message and status_reason. |
Comments suppressed due to low confidence (3)
packages/service-library/src/servicelib/aiohttp/rest_responses.py:35
- The function uses
is_enveloped(data)butis_envelopedis not imported. Add the appropriate import (e.g.,from .rest_utils import is_enveloped) to avoid a NameError.
enveloped_payload = wrap_as_envelope(data) if not is_enveloped(data) else data
packages/service-library/src/servicelib/aiohttp/rest_responses.py:28
HTTP_200_OKis not defined or imported. Either import it (e.g.from aiohttp import HTTP_200_OK) or use a known value likeweb.HTTPOk.status_code.
def create_data_response(data: Any, *, status: int = HTTP_200_OK) -> web.Response:
packages/service-library/tests/aiohttp/test_rest_responses.py:86
- The test function is named
tests_exception_to_response, which does not match pytest'stest_*discovery pattern. Rename it totest_exception_to_responseso it will be executed.
def tests_exception_to_response(
|
@mergify queue |
🛑 The pull request has been removed from the queue
|
074b53e to
84c222b
Compare
matusdrobuliak66
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍
84c222b to
d3b1c51
Compare
d3b1c51 to
e547cd1
Compare
|
|
This pull request has been removed from the queue for the following reason: The merge conditions cannot be satisfied due to failing checks:You may have to fix your CI before adding the pull request to the queue again. |



What do these changes do?
This pull request introduces improvements to error handling and response generation in the
servicelib.aiohttppackage. The changes focus on enhancing the robustness and clarity of HTTP error responses, simplifying the codebase, and updating tests to reflect the new functionality.Error Handling Enhancements:
packages/service-library/src/servicelib/aiohttp/rest_middlewares.py: Added logic to truncate and sanitize HTTP error reasons usingsafe_status_messageto prevent issues like excessively long status lines or multiline reasons. [1] [2]packages/service-library/src/servicelib/aiohttp/rest_responses.py: Introducedsafe_status_messageto truncate HTTP reason phrases and addedstatus_reasonas a separate parameter forcreate_http_errorto distinguish between internal error messages and HTTP status reasons. [1] [2]Response Generation Simplification:
packages/service-library/src/servicelib/aiohttp/rest_responses.py: Refactoredcreate_data_responseto simplify its implementation by removing error handling logic and ensuring all responses are enveloped._collect_http_exceptionsfunction and its related imports.Test Updates:
packages/service-library/tests/aiohttp/test_rest_responses.py: Updated tests forcreate_http_errorto validate the newstatus_reasonparameter and ensure proper handling of various HTTP error classes. [1] [2]Integration Fixes:
services/web/server/src/simcore_service_webserver/director_v2/_controller/_rest_exceptions.py: Updated thestatus_reasonparameter increate_http_errorcalls for better alignment with the new error handling structure.Related issue/s
How to test
Dev-ops