exceptions.py 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. # coding: utf-8
  2. from __future__ import unicode_literals
  3. class CoreAPIException(Exception):
  4. """
  5. A base class for all `coreapi` exceptions.
  6. """
  7. pass
  8. class ParseError(CoreAPIException):
  9. """
  10. Raised when an invalid Core API encoding is encountered.
  11. """
  12. pass
  13. class NoCodecAvailable(CoreAPIException):
  14. """
  15. Raised when there is no available codec that can handle the given media.
  16. """
  17. pass
  18. class NetworkError(CoreAPIException):
  19. """
  20. Raised when the transport layer fails to make a request or get a response.
  21. """
  22. pass
  23. class LinkLookupError(CoreAPIException):
  24. """
  25. Raised when `.action` fails to index a link in the document.
  26. """
  27. pass
  28. class ParameterError(CoreAPIException):
  29. """
  30. Raised when the parameters passed do not match the link fields.
  31. * A required field was not included.
  32. * An unknown field was included.
  33. * A field was passed an invalid type for the link location/encoding.
  34. """
  35. pass
  36. class ErrorMessage(CoreAPIException):
  37. """
  38. Raised when the transition returns an error message.
  39. """
  40. def __init__(self, error):
  41. self.error = error
  42. def __repr__(self):
  43. return '%s(%s)' % (self.__class__.__name__, repr(self.error))
  44. def __str__(self):
  45. return str(self.error)