exceptions.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. # -*- coding: utf-8 -*-
  2. """
  3. flaskbb.core.exceptions
  4. ~~~~~~~~~~~~~~~~~~~~~~~
  5. Exceptions raised by flaskbb.core,
  6. forms the root of all exceptions in
  7. FlaskBB.
  8. :copyright: (c) 2014-2018 the FlaskBB Team
  9. :license: BSD, see LICENSE for more details
  10. """
  11. class BaseFlaskBBError(Exception):
  12. "Root exception for FlaskBB"
  13. class ValidationError(BaseFlaskBBError):
  14. """
  15. Used to signal validation errors for things such as
  16. token verification, user registration, etc.
  17. """
  18. def __init__(self, attribute, reason):
  19. self.attribute = attribute
  20. self.reason = reason
  21. super(ValidationError, self).__init__((attribute, reason))
  22. class StopValidation(BaseFlaskBBError):
  23. """
  24. Raised from validation handlers to signal that
  25. validation should end immediately and no further
  26. processing should be done.
  27. The reasons passed should be an iterable of
  28. tuples consisting of `(attribute, reason)`
  29. Can also be used to communicate all errors
  30. raised during a validation run.
  31. """
  32. def __init__(self, reasons):
  33. self.reasons = reasons
  34. super(StopValidation, self).__init__(reasons)