exceptions.py 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. """Exceptions."""
  2. from __future__ import absolute_import, unicode_literals
  3. from socket import timeout as TimeoutError # noqa
  4. from amqp import ChannelError, ConnectionError, ResourceError
  5. from kombu.five import python_2_unicode_compatible
  6. __all__ = (
  7. 'KombuError', 'OperationalError',
  8. 'NotBoundError', 'MessageStateError', 'TimeoutError',
  9. 'LimitExceeded', 'ConnectionLimitExceeded',
  10. 'ChannelLimitExceeded', 'ConnectionError', 'ChannelError',
  11. 'VersionMismatch', 'SerializerNotInstalled', 'ResourceError',
  12. 'SerializationError', 'EncodeError', 'DecodeError', 'HttpError',
  13. 'InconsistencyError',
  14. )
  15. class KombuError(Exception):
  16. """Common subclass for all Kombu exceptions."""
  17. class OperationalError(KombuError):
  18. """Recoverable message transport connection error."""
  19. class SerializationError(KombuError):
  20. """Failed to serialize/deserialize content."""
  21. class EncodeError(SerializationError):
  22. """Cannot encode object."""
  23. class DecodeError(SerializationError):
  24. """Cannot decode object."""
  25. class NotBoundError(KombuError):
  26. """Trying to call channel dependent method on unbound entity."""
  27. class MessageStateError(KombuError):
  28. """The message has already been acknowledged."""
  29. class LimitExceeded(KombuError):
  30. """Limit exceeded."""
  31. class ConnectionLimitExceeded(LimitExceeded):
  32. """Maximum number of simultaneous connections exceeded."""
  33. class ChannelLimitExceeded(LimitExceeded):
  34. """Maximum number of simultaneous channels exceeded."""
  35. class VersionMismatch(KombuError):
  36. """Library dependency version mismatch."""
  37. class SerializerNotInstalled(KombuError):
  38. """Support for the requested serialization type is not installed."""
  39. class ContentDisallowed(SerializerNotInstalled):
  40. """Consumer does not allow this content-type."""
  41. class InconsistencyError(ConnectionError):
  42. """Data or environment has been found to be inconsistent.
  43. Depending on the cause it may be possible to retry the operation.
  44. """
  45. @python_2_unicode_compatible
  46. class HttpError(Exception):
  47. """HTTP Client Error."""
  48. def __init__(self, code, message=None, response=None):
  49. self.code = code
  50. self.message = message
  51. self.response = response
  52. super(HttpError, self).__init__(code, message, response)
  53. def __str__(self):
  54. return 'HTTP {0.code}: {0.message}'.format(self)