exceptions.py 884 B

123456789101112131415161718192021222324252627282930313233
  1. from rest_framework import status
  2. from rest_framework.exceptions import APIException
  3. class RequestEntityTooLarge(APIException):
  4. status_code = status.HTTP_413_REQUEST_ENTITY_TOO_LARGE
  5. default_detail = "Payload too large."
  6. default_code = "too_large"
  7. class ExternalAPIException(APIException):
  8. def __init__(self, response=None):
  9. self.response = response
  10. detail = (
  11. f"pdns response code: {response.status_code}, body: {response.text}"
  12. if response is not None
  13. else None
  14. )
  15. return super().__init__(detail)
  16. class PDNSException(ExternalAPIException):
  17. pass
  18. class PCHException(ExternalAPIException):
  19. pass
  20. class ConcurrencyException(APIException):
  21. status_code = status.HTTP_429_TOO_MANY_REQUESTS
  22. default_detail = "Too many concurrent requests."
  23. default_code = "concurrency_conflict"