Skip to content

Commit 3c2509d

Browse files
mazzma12fxdgear
authored andcommitted
Add resource type and resource id in TransportError Traceback (elastic#909)
1 parent 300fb83 commit 3c2509d

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

elasticsearch/exceptions.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
'SSLError', 'ConnectionTimeout', 'AuthenticationException', 'AuthorizationException'
55
]
66

7+
78
class ImproperlyConfigured(Exception):
89
"""
910
Exception raised when the config passed to the client is inconsistent or invalid.
@@ -56,12 +57,16 @@ def __str__(self):
5657
try:
5758
if self.info and 'error' in self.info:
5859
if isinstance(self.info['error'], dict):
59-
cause = ', %r' % self.info['error']['root_cause'][0]['reason']
60+
root_cause = self.info['error']['root_cause'][0]
61+
cause = ', '.join(filter(None, [repr(root_cause['reason']), root_cause.get('resource.id'),
62+
root_cause.get('resource.type')]))
63+
6064
else:
61-
cause = ', %r' % self.info['error']
65+
cause = repr(self.info['error'])
6266
except LookupError:
6367
pass
64-
return '%s(%s, %r%s)' % (self.__class__.__name__, self.status_code, self.error, cause)
68+
msg = ', '.join(filter(None, [str(self.status_code), repr(self.error), cause]))
69+
return '%s(%s)' % (self.__class__.__name__, msg)
6570

6671

6772
class ConnectionError(TransportError):
@@ -70,6 +75,7 @@ class ConnectionError(TransportError):
7075
exception from the underlying :class:`~elasticsearch.Connection`
7176
implementation is available as ``.info.``
7277
"""
78+
7379
def __str__(self):
7480
return 'ConnectionError(%s) caused by: %s(%s)' % (
7581
self.error, self.info.__class__.__name__, self.info)
@@ -81,6 +87,7 @@ class SSLError(ConnectionError):
8187

8288
class ConnectionTimeout(ConnectionError):
8389
""" A network timeout. Doesn't cause a node retry by default. """
90+
8491
def __str__(self):
8592
return 'ConnectionTimeout caused by - %s(%s)' % (
8693
self.info.__class__.__name__, self.info)
@@ -105,6 +112,7 @@ class AuthenticationException(TransportError):
105112
class AuthorizationException(TransportError):
106113
""" Exception representing a 403 status code. """
107114

115+
108116
# more generic mappings from status_code to python exceptions
109117
HTTP_EXCEPTIONS = {
110118
400: RequestError,

0 commit comments

Comments
 (0)