2013-11-14 01:08:19 +01:00
|
|
|
__all__ = [
|
|
|
|
|
'ImproperlyConfigured', 'ElasticsearchException', 'SerializationError',
|
2014-03-08 18:50:36 +01:00
|
|
|
'TransportError', 'NotFoundError', 'ConflictError', 'RequestError', 'ConnectionError'
|
2013-11-14 01:08:19 +01:00
|
|
|
]
|
2013-08-25 18:01:45 +02:00
|
|
|
|
|
|
|
|
class ImproperlyConfigured(Exception):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
|
|
|
|
Exception raised when the config passed to the client is inconsistent or invalid.
|
|
|
|
|
"""
|
2013-05-06 16:15:38 +02:00
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class ElasticsearchException(Exception):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
|
|
|
|
Base class for all exceptions raised by this package's operations (doesn't
|
|
|
|
|
apply to :class:`~elasticsearch.ImproperlyConfigured`).
|
|
|
|
|
"""
|
2013-05-01 21:55:44 +02:00
|
|
|
|
|
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class SerializationError(ElasticsearchException):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
2014-03-10 16:10:17 +01:00
|
|
|
Data passed in failed to serialize properly in the ``Serializer`` being
|
2014-03-08 18:50:36 +01:00
|
|
|
used.
|
|
|
|
|
"""
|
2013-05-02 23:42:11 +02:00
|
|
|
|
|
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class TransportError(ElasticsearchException):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
|
|
|
|
Exception raised when ES returns a non-OK (>=400) HTTP status code. Or when
|
|
|
|
|
an actual connection error happens; in that case the ``status_code`` will
|
|
|
|
|
be set to ``'N/A'``.
|
|
|
|
|
"""
|
2013-07-30 14:25:10 +02:00
|
|
|
@property
|
|
|
|
|
def status_code(self):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
|
|
|
|
The HTTP status code of the response that precipitated the error or
|
|
|
|
|
``'N/A'`` if not applicable.
|
|
|
|
|
"""
|
2013-07-30 14:25:10 +02:00
|
|
|
return self.args[0]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def error(self):
|
|
|
|
|
""" A string error message. """
|
|
|
|
|
return self.args[1]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def info(self):
|
2014-03-08 18:50:36 +01:00
|
|
|
""" Dict of returned error info from ES, where available. """
|
2013-07-30 14:25:10 +02:00
|
|
|
return self.args[2]
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
2014-02-06 01:15:41 +01:00
|
|
|
return 'TransportError(%s, %r)' % (self.status_code, self.error)
|
2013-05-01 21:55:44 +02:00
|
|
|
|
|
|
|
|
|
2013-05-19 18:45:12 +02:00
|
|
|
class ConnectionError(TransportError):
|
2014-03-08 18:50:36 +01:00
|
|
|
"""
|
|
|
|
|
Error raised when there was an exception while talking to ES. Original
|
|
|
|
|
exception from the underlying :class:`~elasticsearch.Connection`
|
|
|
|
|
implementation is available as ``.info.``
|
|
|
|
|
"""
|
2013-07-30 16:50:36 +02:00
|
|
|
def __str__(self):
|
|
|
|
|
return 'ConnectionError(%s) caused by: %s(%s)' % (
|
|
|
|
|
self.error, self.info.__class__.__name__, self.info)
|
2013-05-19 18:45:12 +02:00
|
|
|
|
|
|
|
|
|
2013-05-01 21:55:44 +02:00
|
|
|
class NotFoundError(TransportError):
|
2014-03-08 18:50:36 +01:00
|
|
|
""" Exception representing a 404 status code. """
|
2013-05-01 21:55:44 +02:00
|
|
|
|
|
|
|
|
|
2013-11-14 01:08:19 +01:00
|
|
|
class ConflictError(TransportError):
|
2014-03-08 18:50:36 +01:00
|
|
|
""" Exception representing a 409 status code. """
|
2013-11-14 01:08:19 +01:00
|
|
|
|
|
|
|
|
|
|
|
|
|
class RequestError(TransportError):
|
2014-03-08 18:50:36 +01:00
|
|
|
""" Exception representing a 400 status code. """
|
2013-11-14 01:08:19 +01:00
|
|
|
|
2013-07-30 14:25:10 +02:00
|
|
|
# more generic mappings from status_code to python exceptions
|
2013-05-01 21:55:44 +02:00
|
|
|
HTTP_EXCEPTIONS = {
|
2013-11-14 01:08:19 +01:00
|
|
|
400: RequestError,
|
2013-05-01 21:55:44 +02:00
|
|
|
404: NotFoundError,
|
2013-11-14 01:08:19 +01:00
|
|
|
409: ConflictError,
|
2013-05-01 21:55:44 +02:00
|
|
|
}
|