Skip to content

Commit

Permalink
handle details "null" (#19430)
Browse files Browse the repository at this point in the history
* handle details "null"

* update
  • Loading branch information
xiangyan99 authored Jul 8, 2021
1 parent 59a3af4 commit 8273668
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion sdk/core/azure-core/azure/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ def __init__(self, json_object):

# details is recursive of this very format
self.details = [] # type: List[ODataV4Format]
for detail_node in json_object.get(cls.DETAILS_LABEL, []):
for detail_node in json_object.get(cls.DETAILS_LABEL) or []:
try:
self.details.append(self.__class__(detail_node))
except Exception: # pylint: disable=broad-except
Expand Down
13 changes: 13 additions & 0 deletions sdk/core/azure-core/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -250,3 +250,16 @@ def test_broken_odata_details(self):
}
exp = HttpResponseError(response=_build_response(json.dumps(message).encode("utf-8")))
assert exp.error.code == "Conflict"

def test_null_odata_details(self):
message = {
"error": {
"code": "501",
"message": "message",
"target": None,
"details": None,
"innererror": None,
}
}
exp = HttpResponseError(response=_build_response(json.dumps(message).encode("utf-8")))
assert exp.error.code == "501"

0 comments on commit 8273668

Please sign in to comment.