exceptions.py 1.2 KB

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