Skip to content

Commit 97d332e

Browse files
committed
cleanup
1 parent b086afc commit 97d332e

File tree

1 file changed

+14
-13
lines changed

1 file changed

+14
-13
lines changed

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

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
"""Utils to check, convert and compose server responses for the RESTApi"""
22

33
import inspect
4-
from typing import Any, cast
4+
from typing import Any
55

66
from aiohttp import web, web_exceptions
77
from aiohttp.web_exceptions import HTTPError, HTTPException
88
from common_library.error_codes import ErrorCodeStr
99
from common_library.json_serialization import json_dumps
10-
from models_library.basic_types import IDStr
1110
from models_library.rest_error import ErrorGet, ErrorItemType
1211
from servicelib.rest_constants import RESPONSE_MODEL_POLICY
1312

@@ -65,24 +64,26 @@ def create_http_error(
6564
if not isinstance(errors, list):
6665
errors = [errors]
6766

68-
support_id: IDStr | None = cast(IDStr, error_code) if error_code else None
69-
7067
is_internal_error: bool = http_error_cls == web.HTTPInternalServerError
7168
default_message = reason or get_code_description(http_error_cls.status_code)
7269

7370
if is_internal_error and skip_internal_error_details:
74-
error = ErrorGet(
75-
status=http_error_cls.status_code,
76-
message=default_message,
77-
support_id=support_id,
71+
error = ErrorGet.model_validate(
72+
{
73+
"status": http_error_cls.status_code,
74+
"message": default_message,
75+
"support_id": error_code,
76+
}
7877
)
7978
else:
8079
items = [ErrorItemType.from_error(err) for err in errors]
81-
error = ErrorGet(
82-
errors=items, # NOTE: deprecated!
83-
status=http_error_cls.status_code,
84-
message=default_message,
85-
support_id=support_id,
80+
error = ErrorGet.model_validate(
81+
{
82+
"errors": items, # NOTE: deprecated!
83+
"status": http_error_cls.status_code,
84+
"message": default_message,
85+
"support_id": error_code,
86+
}
8687
)
8788

8889
assert not http_error_cls.empty_body # nosec

0 commit comments

Comments
 (0)