exceptions.py 825 B

12345678910111213141516171819202122232425262728
  1. import json
  2. from json import JSONDecodeError
  3. from rest_framework import status
  4. from rest_framework.exceptions import APIException, ValidationError
  5. class RequestEntityTooLarge(APIException):
  6. status_code = status.HTTP_413_REQUEST_ENTITY_TOO_LARGE
  7. default_detail = 'Payload too large.'
  8. default_code = 'too_large'
  9. class PDNSValidationError(ValidationError):
  10. status_code = 422
  11. def __init__(self, response=None):
  12. try:
  13. detail = json.loads(response.text)['error']
  14. except JSONDecodeError:
  15. detail = response.text
  16. return super().__init__(detail=detail, code='invalid')
  17. class PDNSException(APIException):
  18. def __init__(self, response=None):
  19. return super().__init__(f'pdns response code: {response.status_code}, pdns response body: {response.text}')