Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions elasticsearch/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
'SSLError', 'ConnectionTimeout', 'AuthenticationException', 'AuthorizationException'
]


class ImproperlyConfigured(Exception):
"""
Exception raised when the config passed to the client is inconsistent or invalid.
Expand Down Expand Up @@ -56,12 +57,16 @@ def __str__(self):
try:
if self.info and 'error' in self.info:
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:
cause = ', %r' % self.info['error']
cause = repr(self.info['error'])
except LookupError:
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):
Expand All @@ -70,6 +75,7 @@ class ConnectionError(TransportError):
exception from the underlying :class:`~elasticsearch.Connection`
implementation is available as ``.info.``
"""

def __str__(self):
return 'ConnectionError(%s) caused by: %s(%s)' % (
self.error, self.info.__class__.__name__, self.info)
Expand All @@ -81,6 +87,7 @@ class SSLError(ConnectionError):

class ConnectionTimeout(ConnectionError):
""" A network timeout. Doesn't cause a node retry by default. """

def __str__(self):
return 'ConnectionTimeout caused by - %s(%s)' % (
self.info.__class__.__name__, self.info)
Expand All @@ -105,6 +112,7 @@ class AuthenticationException(TransportError):
class AuthorizationException(TransportError):
""" Exception representing a 403 status code. """


# more generic mappings from status_code to python exceptions
HTTP_EXCEPTIONS = {
400: RequestError,
Expand Down