44 'SSLError' , 'ConnectionTimeout' , 'AuthenticationException' , 'AuthorizationException'
55]
66
7+
78class 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
6772class 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
8288class 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):
105112class AuthorizationException (TransportError ):
106113 """ Exception representing a 403 status code. """
107114
115+
108116# more generic mappings from status_code to python exceptions
109117HTTP_EXCEPTIONS = {
110118 400 : RequestError ,
0 commit comments