Skip to content

Commit 9686966

Browse files
authored
show detailed error (#18229)
* show detailed error * update * update * update * update
1 parent 7349162 commit 9686966

File tree

2 files changed

+31
-5
lines changed

2 files changed

+31
-5
lines changed

sdk/core/azure-core/azure/core/exceptions.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,28 @@ class ODataV4Format(object):
107107
108108
http://docs.oasis-open.org/odata/odata-json-format/v4.0/os/odata-json-format-v4.0-os.html#_Toc372793091
109109
110+
Example of JSON:
111+
112+
error: {
113+
"code": "ValidationError",
114+
"message": "One or more fields contain incorrect values: ",
115+
"details": [
116+
{
117+
"code": "ValidationError",
118+
"target": "representation",
119+
"message": "Parsing error(s): String '' does not match regex pattern '^[^{}/ :]+(?: :\\\\d+)?$'.
120+
Path 'host', line 1, position 297."
121+
},
122+
{
123+
"code": "ValidationError",
124+
"target": "representation",
125+
"message": "Parsing error(s): The input OpenAPI file is not valid for the OpenAPI specificate
126+
https: //github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md
127+
(schema https://github.com/OAI/OpenAPI-Specification/blob/master/schemas/v2.0/schema.json)."
128+
}
129+
]
130+
}
131+
110132
:param dict json_object: A Python dict representing a ODataV4 JSON
111133
:ivar str ~.code: Its value is a service-defined error code.
112134
This code serves as a sub-status for the HTTP error code specified in the response.
@@ -160,7 +182,11 @@ def error(self):
160182
return self
161183

162184
def __str__(self):
163-
return "({}) {}".format(self.code, self.message)
185+
return "({}) {}\n{}".format(
186+
self.code,
187+
self.message,
188+
self.message_details()
189+
)
164190

165191
def message_details(self):
166192
"""Return a detailled string of the error.

sdk/core/azure-core/tests/test_exceptions.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ def test_deserialized_httpresponse_error_code(self):
122122
}
123123
response = _build_response(json.dumps(message).encode("utf-8"))
124124
error = FakeHttpResponse(response, FakeErrorOne())
125-
assert error.message == "(FakeErrorOne) A fake error"
126-
assert str(error.error) == "(FakeErrorOne) A fake error"
125+
assert "(FakeErrorOne) A fake error" in error.message
126+
assert "(FakeErrorOne) A fake error" in str(error.error)
127127
assert error.error.code == "FakeErrorOne"
128128
assert error.error.message == "A fake error"
129129
assert error.response is response
@@ -149,8 +149,8 @@ def test_deserialized_httpresponse_error_message(self):
149149
}
150150
response = _build_response(json.dumps(message).encode("utf-8"))
151151
error = FakeHttpResponse(response, FakeErrorTwo())
152-
assert error.message == "(FakeErrorTwo) A different fake error"
153-
assert str(error.error) == "(FakeErrorTwo) A different fake error"
152+
assert "(FakeErrorTwo) A different fake error" in error.message
153+
assert "(FakeErrorTwo) A different fake error" in str(error.error)
154154
assert error.error.code == "FakeErrorTwo"
155155
assert error.error.message == "A different fake error"
156156
assert error.response is response

0 commit comments

Comments
 (0)