Skip to content

Commit c4c8628

Browse files
committed
cleanup
1 parent dc0e69d commit c4c8628

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

packages/service-library/src/servicelib/aiohttp/rest_middlewares.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,14 +87,18 @@ def _handle_http_error(
8787
) -> web.HTTPError:
8888
"""Handle standard HTTP errors by ensuring they're properly formatted."""
8989
assert request # nosec
90+
assert not exception.empty_body, "HTTPError should not have an empty body" # nosec
91+
9092
exception.content_type = MIMETYPE_APPLICATION_JSON
9193
if exception.reason:
9294
exception.set_status(
9395
exception.status, safe_status_message(message=exception.reason)
9496
)
9597

9698
if not exception.text or not is_enveloped_from_text(exception.text):
97-
error_message = exception.text or exception.reason or "Unexpected error"
99+
# NOTE: aiohttp.HTTPException creates `text = f"{self.status}: {self.reason}"`
100+
# We do not like for the user to pop up a message like "401: You are not authorized"
101+
error_message = exception.reason or exception.text or "Unexpected error"
98102
error_model = ErrorGet(
99103
errors=[
100104
ErrorItemType.from_error(exception),

0 commit comments

Comments
 (0)