Add resource type and resource id in TransportError Traceback (#909)
This commit is contained in:
@@ -4,6 +4,7 @@ __all__ = [
|
|||||||
'SSLError', 'ConnectionTimeout', 'AuthenticationException', 'AuthorizationException'
|
'SSLError', 'ConnectionTimeout', 'AuthenticationException', 'AuthorizationException'
|
||||||
]
|
]
|
||||||
|
|
||||||
|
|
||||||
class ImproperlyConfigured(Exception):
|
class ImproperlyConfigured(Exception):
|
||||||
"""
|
"""
|
||||||
Exception raised when the config passed to the client is inconsistent or invalid.
|
Exception raised when the config passed to the client is inconsistent or invalid.
|
||||||
@@ -56,12 +57,16 @@ class TransportError(ElasticsearchException):
|
|||||||
try:
|
try:
|
||||||
if self.info and 'error' in self.info:
|
if self.info and 'error' in self.info:
|
||||||
if isinstance(self.info['error'], dict):
|
if isinstance(self.info['error'], dict):
|
||||||
cause = ', %r' % self.info['error']['root_cause'][0]['reason']
|
root_cause = self.info['error']['root_cause'][0]
|
||||||
|
cause = ', '.join(filter(None, [repr(root_cause['reason']), root_cause.get('resource.id'),
|
||||||
|
root_cause.get('resource.type')]))
|
||||||
|
|
||||||
else:
|
else:
|
||||||
cause = ', %r' % self.info['error']
|
cause = repr(self.info['error'])
|
||||||
except LookupError:
|
except LookupError:
|
||||||
pass
|
pass
|
||||||
return '%s(%s, %r%s)' % (self.__class__.__name__, self.status_code, self.error, cause)
|
msg = ', '.join(filter(None, [str(self.status_code), repr(self.error), cause]))
|
||||||
|
return '%s(%s)' % (self.__class__.__name__, msg)
|
||||||
|
|
||||||
|
|
||||||
class ConnectionError(TransportError):
|
class ConnectionError(TransportError):
|
||||||
@@ -70,6 +75,7 @@ class ConnectionError(TransportError):
|
|||||||
exception from the underlying :class:`~elasticsearch.Connection`
|
exception from the underlying :class:`~elasticsearch.Connection`
|
||||||
implementation is available as ``.info.``
|
implementation is available as ``.info.``
|
||||||
"""
|
"""
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'ConnectionError(%s) caused by: %s(%s)' % (
|
return 'ConnectionError(%s) caused by: %s(%s)' % (
|
||||||
self.error, self.info.__class__.__name__, self.info)
|
self.error, self.info.__class__.__name__, self.info)
|
||||||
@@ -81,6 +87,7 @@ class SSLError(ConnectionError):
|
|||||||
|
|
||||||
class ConnectionTimeout(ConnectionError):
|
class ConnectionTimeout(ConnectionError):
|
||||||
""" A network timeout. Doesn't cause a node retry by default. """
|
""" A network timeout. Doesn't cause a node retry by default. """
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
return 'ConnectionTimeout caused by - %s(%s)' % (
|
return 'ConnectionTimeout caused by - %s(%s)' % (
|
||||||
self.info.__class__.__name__, self.info)
|
self.info.__class__.__name__, self.info)
|
||||||
@@ -105,6 +112,7 @@ class AuthenticationException(TransportError):
|
|||||||
class AuthorizationException(TransportError):
|
class AuthorizationException(TransportError):
|
||||||
""" Exception representing a 403 status code. """
|
""" Exception representing a 403 status code. """
|
||||||
|
|
||||||
|
|
||||||
# more generic mappings from status_code to python exceptions
|
# more generic mappings from status_code to python exceptions
|
||||||
HTTP_EXCEPTIONS = {
|
HTTP_EXCEPTIONS = {
|
||||||
400: RequestError,
|
400: RequestError,
|
||||||
|
|||||||
Reference in New Issue
Block a user