exceptions.py 718 B

123456789101112131415161718192021222324252627282930
  1. __doc__ = """ Exceptions and special return codes. """
  2. BREAK = "__break"
  3. CONT = "__continue"
  4. class ApiError(Exception):
  5. """ Base class for all exceptions expecting an API response. """
  6. status_code = 400
  7. msg = "An undefined error occurred."
  8. def __init__(self, msg=None):
  9. if msg is not None:
  10. self.msg = msg
  11. def to_json(self):
  12. return {
  13. "message": self.msg,
  14. "status_code": self.status_code,
  15. }
  16. class ConfigError(ApiError):
  17. """ Raised when a malformed configuration is detected. """
  18. status_code = 500
  19. class UpstreamError(ApiError):
  20. """ Raised when an external service responds with an error code. """
  21. status_code = 500