exceptions.py 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. from rest_framework import status
  2. from rest_framework.exceptions import APIException
  3. __all__ = (
  4. 'AbortRequest',
  5. 'AbortTransaction',
  6. 'PermissionsViolation',
  7. 'RQWorkerNotRunningException',
  8. )
  9. class AbortTransaction(Exception):
  10. """
  11. A dummy exception used to trigger a database transaction rollback.
  12. """
  13. pass
  14. class AbortRequest(Exception):
  15. """
  16. Raised to cleanly abort a request (for example, by a pre_save signal receiver).
  17. """
  18. def __init__(self, message):
  19. self.message = message
  20. class PermissionsViolation(Exception):
  21. """
  22. Raised when an operation was prevented because it would violate the
  23. allowed permissions.
  24. """
  25. message = "Operation failed due to object-level permissions violation"
  26. class RQWorkerNotRunningException(APIException):
  27. """
  28. Indicates the temporary inability to enqueue a new task (e.g. custom script execution) because no RQ worker
  29. processes are currently running.
  30. """
  31. status_code = status.HTTP_503_SERVICE_UNAVAILABLE
  32. default_detail = 'Unable to process request: RQ worker process not running.'
  33. default_code = 'rq_worker_not_running'