Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 27 additions & 1 deletion sdk/core/azure-core/azure/core/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,28 @@ class ODataV4Format(object):

http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091

Example of JSON:

error: {
"code": "ValidationError",
"message": "One or more fields contain incorrect values: ",
"details": [
{
"code": "ValidationError",
"target": "representation",
"message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\\\d+)?$'.
Path 'host', line 1, position 297."
},
{
"code": "ValidationError",
"target": "representation",
"message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate
https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
(schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)."
}
]
}

:param dict json_object: A Python dict representing a ODataV4 JSON
:ivar str ~.code: Its value is a service-defined error code.
This code serves as a sub-status for the HTTP error code specified in the response.
Expand Down Expand Up @@ -160,7 +182,11 @@ def error(self):
return self

def __str__(self):
return "({}) {}".format(self.code, self.message)
return "({}) {}\n{}".format(
self.code,
self.message,
self.message_details()
)

def message_details(self):
"""Return a detailled string of the error.
Expand Down
8 changes: 4 additions & 4 deletions sdk/core/azure-core/tests/test_exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def test_deserialized_httpresponse_error_code(self):
}
response = _build_response(json.dumps(message).encode("utf-8"))
error = FakeHttpResponse(response, FakeErrorOne())
assert error.message == "(FakeErrorOne) A fake error"
assert str(error.error) == "(FakeErrorOne) A fake error"
assert "(FakeErrorOne) A fake error" in error.message
assert "(FakeErrorOne) A fake error" in str(error.error)
assert error.error.code == "FakeErrorOne"
assert error.error.message == "A fake error"
assert error.response is response
Expand All @@ -149,8 +149,8 @@ def test_deserialized_httpresponse_error_message(self):
}
response = _build_response(json.dumps(message).encode("utf-8"))
error = FakeHttpResponse(response, FakeErrorTwo())
assert error.message == "(FakeErrorTwo) A different fake error"
assert str(error.error) == "(FakeErrorTwo) A different fake error"
assert "(FakeErrorTwo) A different fake error" in error.message
assert "(FakeErrorTwo) A different fake error" in str(error.error)
assert error.error.code == "FakeErrorTwo"
assert error.error.message == "A different fake error"
assert error.response is response
Expand Down