Skip to content

Commit

Permalink
🐛CDK: Fix of generate the error message using _try_get_error based on…
Browse files Browse the repository at this point in the history
… list of errors (#32545)
  • Loading branch information
yevhenii-ldv authored Nov 17, 2023
1 parent f8ae6f6 commit d475beb
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,8 @@ def _try_get_error(value: Any) -> Any:
if isinstance(value, str):
return value
elif isinstance(value, list):
return ", ".join(_try_get_error(v) for v in value)
error_list = [_try_get_error(v) for v in value]
return ", ".join(v for v in error_list if v is not None)
elif isinstance(value, dict):
new_value = (
value.get("message")
Expand All @@ -547,6 +548,8 @@ def _try_get_error(value: Any) -> Any:
or value.get("errors")
or value.get("failures")
or value.get("failure")
or value.get("details")
or value.get("detail")
)
return _try_get_error(new_value)
return None
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -686,14 +686,19 @@ def test_raise_on_http_errors(mocker, error):
({"error": {"message": "something broke"}}, "something broke"),
({"error": "err-001", "message": "something broke"}, "something broke"),
({"failure": {"message": "something broke"}}, "something broke"),
({"detail": {"message": "something broke"}}, "something broke"),
({"error": {"errors": [{"message": "one"}, {"message": "two"}, {"message": "three"}]}}, "one, two, three"),
({"errors": ["one", "two", "three"]}, "one, two, three"),
({"errors": [None, {}, "third error", 9002.09]}, "third error"),
({"messages": ["one", "two", "three"]}, "one, two, three"),
({"errors": [{"message": "one"}, {"message": "two"}, {"message": "three"}]}, "one, two, three"),
({"error": [{"message": "one"}, {"message": "two"}, {"message": "three"}]}, "one, two, three"),
({"errors": [{"error": "one"}, {"error": "two"}, {"error": "three"}]}, "one, two, three"),
({"failures": [{"message": "one"}, {"message": "two"}, {"message": "three"}]}, "one, two, three"),
({"details": [{"message": "one"}, {"message": "two"}, {"message": "three"}]}, "one, two, three"),
({"details": ["one", 10087, True]}, "one"),
(["one", "two", "three"], "one, two, three"),
({"detail": False}, None),
([{"error": "one"}, {"error": "two"}, {"error": "three"}], "one, two, three"),
({"error": True}, None),
({"something_else": "hi"}, None),
Expand Down

0 comments on commit d475beb

Please sign in to comment.