Added documentation for exceptions raised by elasticsearch-py
Fixes #58, thanks, willkg, for the report!
This commit is contained in:
+9
-6
@@ -3,13 +3,16 @@
|
|||||||
API Documentation
|
API Documentation
|
||||||
=================
|
=================
|
||||||
|
|
||||||
.. note::
|
All the API calls map the raw REST api as closely as possible, including the
|
||||||
|
distinction between required and optional arguments to the calls. This means
|
||||||
|
that the code makes distinction between positional and keyword arguments; we,
|
||||||
|
however, recommend that people *use keyword arguments for all calls for
|
||||||
|
consistency and safety*.
|
||||||
|
|
||||||
All the API calls map the raw REST api as closely as possible, including
|
An API call is considered successful (and will return a response) if
|
||||||
the distinction between required and optional arguments to the calls. This
|
elasticsearch returns a 2XX response. Otherwise an instance of
|
||||||
means that the code makes distinction between positional and keyword arguments;
|
:class:`~elasticsearch.TransportError` (or a more specific subclass) will be
|
||||||
we, however, recommend that people use keyword arguments for all calls for
|
raised. You can see other exception and error states in :ref:`exceptions`.
|
||||||
consistency and safety.
|
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,20 @@
|
|||||||
|
.. _exceptions:
|
||||||
|
|
||||||
|
Exceptions
|
||||||
|
==========
|
||||||
|
|
||||||
|
.. py:module:: elasticsearch
|
||||||
|
|
||||||
|
.. autoclass:: ImproperlyConfigured
|
||||||
|
|
||||||
|
.. autoclass:: ElasticsearchException
|
||||||
|
|
||||||
|
.. autoclass:: SerializationError(ElasticsearchException)
|
||||||
|
|
||||||
|
.. autoclass:: TransportError(ElasticsearchException)
|
||||||
|
:members:
|
||||||
|
|
||||||
|
.. autoclass:: NotFoundError(TransportError)
|
||||||
|
.. autoclass:: ConflictError(TransportError)
|
||||||
|
.. autoclass:: RequestError(TransportError)
|
||||||
|
.. autoclass:: ConnectionError(TransportError)
|
||||||
@@ -123,6 +123,7 @@ Contents
|
|||||||
:maxdepth: 2
|
:maxdepth: 2
|
||||||
|
|
||||||
api
|
api
|
||||||
|
exceptions
|
||||||
connection
|
connection
|
||||||
transports
|
transports
|
||||||
helpers
|
helpers
|
||||||
|
|||||||
+30
-11
@@ -1,24 +1,39 @@
|
|||||||
__all__ = [
|
__all__ = [
|
||||||
'ImproperlyConfigured', 'ElasticsearchException', 'SerializationError',
|
'ImproperlyConfigured', 'ElasticsearchException', 'SerializationError',
|
||||||
'TransportError', 'NotFoundError', 'ConflictError', 'RequestError'
|
'TransportError', 'NotFoundError', 'ConflictError', 'RequestError', 'ConnectionError'
|
||||||
]
|
]
|
||||||
|
|
||||||
class ImproperlyConfigured(Exception):
|
class ImproperlyConfigured(Exception):
|
||||||
pass
|
"""
|
||||||
|
Exception raised when the config passed to the client is inconsistent or invalid.
|
||||||
|
"""
|
||||||
|
|
||||||
class ElasticsearchException(Exception):
|
class ElasticsearchException(Exception):
|
||||||
pass
|
"""
|
||||||
|
Base class for all exceptions raised by this package's operations (doesn't
|
||||||
|
apply to :class:`~elasticsearch.ImproperlyConfigured`).
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class SerializationError(ElasticsearchException):
|
class SerializationError(ElasticsearchException):
|
||||||
pass
|
"""
|
||||||
|
Data passed int failed to serialize properly in the ``Serializer`` being
|
||||||
|
used.
|
||||||
|
"""
|
||||||
|
|
||||||
|
|
||||||
class TransportError(ElasticsearchException):
|
class TransportError(ElasticsearchException):
|
||||||
""" Exception raised when ES returns a non-OK (>=400) HTTP status code. """
|
"""
|
||||||
|
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'``.
|
||||||
|
"""
|
||||||
@property
|
@property
|
||||||
def status_code(self):
|
def status_code(self):
|
||||||
""" The HTTP status code of the response that precipitated the error. """
|
"""
|
||||||
|
The HTTP status code of the response that precipitated the error or
|
||||||
|
``'N/A'`` if not applicable.
|
||||||
|
"""
|
||||||
return self.args[0]
|
return self.args[0]
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@@ -28,7 +43,7 @@ class TransportError(ElasticsearchException):
|
|||||||
|
|
||||||
@property
|
@property
|
||||||
def info(self):
|
def info(self):
|
||||||
""" Dict of returned error info from ES, where applicable. """
|
""" Dict of returned error info from ES, where available. """
|
||||||
return self.args[2]
|
return self.args[2]
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
@@ -36,22 +51,26 @@ class TransportError(ElasticsearchException):
|
|||||||
|
|
||||||
|
|
||||||
class ConnectionError(TransportError):
|
class ConnectionError(TransportError):
|
||||||
""" Error raised when there was an exception while talking to ES. """
|
"""
|
||||||
|
Error raised when there was an exception while talking to ES. Original
|
||||||
|
exception from the underlying :class:`~elasticsearch.Connection`
|
||||||
|
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)
|
||||||
|
|
||||||
|
|
||||||
class NotFoundError(TransportError):
|
class NotFoundError(TransportError):
|
||||||
pass
|
""" Exception representing a 404 status code. """
|
||||||
|
|
||||||
|
|
||||||
class ConflictError(TransportError):
|
class ConflictError(TransportError):
|
||||||
pass
|
""" Exception representing a 409 status code. """
|
||||||
|
|
||||||
|
|
||||||
class RequestError(TransportError):
|
class RequestError(TransportError):
|
||||||
pass
|
""" Exception representing a 400 status code. """
|
||||||
|
|
||||||
# more generic mappings from status_code to python exceptions
|
# more generic mappings from status_code to python exceptions
|
||||||
HTTP_EXCEPTIONS = {
|
HTTP_EXCEPTIONS = {
|
||||||
|
|||||||
Reference in New Issue
Block a user