Skip to content

Commit b3bbdcc

Browse files
committed
Fix node failure test cases
1 parent a3bbb27 commit b3bbdcc

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

client/client.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"""
44

55
import asyncio
6+
import sys
67
from typing import Any, List, Tuple
78
from uuid import UUID
89
from fastapi import status
@@ -241,14 +242,23 @@ def summarize_failure(hub_results: List[Any]) -> Tuple[List[str], int]:
241242
- A list of cause strings (included in the details of the ETSI exception)
242243
- The status code to be used in the ETSI exception, the worst of the peer status codes.
243244
"""
245+
print("Summarizing failures from hub results:", file=sys.stderr) ### DEBUG
244246
status_code = None
245247
causes = []
246248
for hub_result in hub_results:
247249
if isinstance(hub_result, Exception):
248250
causes.append(str(hub_result))
249251
if isinstance(hub_result, exceptions.DSKEException):
250252
if status_code is None or hub_result.status_code > status_code:
253+
print(
254+
f"New worst status code: {hub_result.status_code} from hub result: {hub_result}",
255+
file=sys.stderr,
256+
) ### DEBUG
251257
status_code = hub_result.status_code
252258
if status_code is None:
253-
status_code = status.HTTP_500_INTERNAL_SERVER_ERROR
259+
print
260+
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
261+
print(
262+
f"Final summarized status code: {status_code}", file=sys.stderr
263+
) ### DEBUG
254264
return (causes, status_code)

common/exceptions.py

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ def __init__(
6262
response: str | None = None,
6363
exception: str | None = None,
6464
):
65+
if status_code is None:
66+
status_code = status.HTTP_503_SERVICE_UNAVAILABLE
6567
details = {}
6668
details["method"] = method
6769
details["url"] = url
@@ -71,8 +73,7 @@ def __init__(
7173
details["params"] = params
7274
if data is not None:
7375
details["data"] = data
74-
if status_code is not None:
75-
details["status_code"] = status_code
76+
details["status_code"] = status_code
7677
if response is not None:
7778
details["response"] = response
7879
if exception is not None:
@@ -86,11 +87,7 @@ def __init__(
8687
except Exception: # pylint: disable=broad-except
8788
pass
8889
message = f"HTTP request failed ({method} {url}: {status_code}{explain})."
89-
super().__init__(
90-
status_code=status_code or status.HTTP_500_INTERNAL_SERVER_ERROR,
91-
message=message,
92-
details=details,
93-
)
90+
super().__init__(status_code=status_code, message=message, details=details)
9491

9592

9693
class InvalidKeyIDError(DSKEException):

0 commit comments

Comments
 (0)