2013-09-28 15:45:43 +02:00
|
|
|
__all__ = ['ImproperlyConfigured', 'ElasticsearchException', 'SerializationError', 'TransportError', 'NotFoundError']
|
2013-08-25 18:01:45 +02:00
|
|
|
|
|
|
|
|
class ImproperlyConfigured(Exception):
|
|
|
|
|
pass
|
2013-05-06 16:15:38 +02:00
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class ElasticsearchException(Exception):
|
2013-05-01 21:55:44 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class SerializationError(ElasticsearchException):
|
2013-05-02 23:42:11 +02:00
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
2013-09-28 15:45:43 +02:00
|
|
|
class TransportError(ElasticsearchException):
|
2013-07-30 14:25:10 +02:00
|
|
|
""" Exception raised when ES returns a non-OK (>=400) HTTP status code. """
|
|
|
|
|
@property
|
|
|
|
|
def status_code(self):
|
|
|
|
|
""" The HTTP status code of the response that precipitated the error. """
|
|
|
|
|
return self.args[0]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def error(self):
|
|
|
|
|
""" A string error message. """
|
|
|
|
|
return self.args[1]
|
|
|
|
|
|
|
|
|
|
@property
|
|
|
|
|
def info(self):
|
|
|
|
|
""" Dict of returned error info from ES, where applicable. """
|
|
|
|
|
return self.args[2]
|
|
|
|
|
|
|
|
|
|
def __str__(self):
|
|
|
|
|
return 'TransportError(%d, %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):
|
2013-07-30 14:25:10 +02:00
|
|
|
""" Error raised when there was an exception while talking to ES. """
|
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):
|
2013-07-30 14:25:10 +02:00
|
|
|
pass
|
2013-05-01 21:55:44 +02: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 = {
|
|
|
|
|
404: NotFoundError,
|
|
|
|
|
}
|