Skip to content

Commit b41c2d1

Browse files
committed
Jac/user import (#1086)
* Include the url of the request that got an error in the response. Makes it much easier to debug. * Add user import logic, and user import example in samples
1 parent 3bd0440 commit b41c2d1

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

tableauserverclient/server/endpoint/exceptions.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -6,29 +6,34 @@ class TableauError(Exception):
66

77

88
class ServerResponseError(TableauError):
9-
def __init__(self, code, summary, detail):
9+
def __init__(self, code, summary, detail, url=None):
1010
self.code = code
1111
self.summary = summary
1212
self.detail = detail
13+
self.url = url
1314
super(ServerResponseError, self).__init__(str(self))
1415

1516
def __str__(self):
1617
return "\n\n\t{0}: {1}\n\t\t{2}".format(self.code, self.summary, self.detail)
1718

1819
@classmethod
19-
def from_response(cls, resp, ns):
20+
def from_response(cls, resp, ns, url=None):
2021
# Check elements exist before .text
2122
parsed_response = fromstring(resp)
22-
error_response = cls(
23-
parsed_response.find("t:error", namespaces=ns).get("code", ""),
24-
parsed_response.find(".//t:summary", namespaces=ns).text,
25-
parsed_response.find(".//t:detail", namespaces=ns).text,
26-
)
23+
try:
24+
error_response = cls(
25+
parsed_response.find("t:error", namespaces=ns).get("code", ""),
26+
parsed_response.find(".//t:summary", namespaces=ns).text,
27+
parsed_response.find(".//t:detail", namespaces=ns).text,
28+
url,
29+
)
30+
except Exception as e:
31+
raise NonXMLResponseError(resp)
2732
return error_response
2833

2934

3035
class InternalServerError(TableauError):
31-
def __init__(self, server_response, request_url):
36+
def __init__(self, server_response, request_url: str = None):
3237
self.code = server_response.status_code
3338
self.content = server_response.content
3439
self.url = request_url or "server"

0 commit comments

Comments
 (0)