diff --git a/sdk/core/azure-core/azure/core/exceptions.py b/sdk/core/azure-core/azure/core/exceptions.py index 4af83e9b3683..814b9ed18f39 100644 --- a/sdk/core/azure-core/azure/core/exceptions.py +++ b/sdk/core/azure-core/azure/core/exceptions.py @@ -163,7 +163,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 diff --git a/sdk/core/azure-core/tests/test_exceptions.py b/sdk/core/azure-core/tests/test_exceptions.py index 85b414a16b93..399c559cf944 100644 --- a/sdk/core/azure-core/tests/test_exceptions.py +++ b/sdk/core/azure-core/tests/test_exceptions.py @@ -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" \ No newline at end of file