exceptions.py 498 B

1234567891011121314151617
  1. import json
  2. from json import JSONDecodeError
  3. from rest_framework.exceptions import APIException
  4. class PdnsException(APIException):
  5. def __init__(self, response=None, detail=None, status=None):
  6. self.status_code = status or response.status_code
  7. if detail:
  8. self.detail = detail
  9. else:
  10. try:
  11. self.detail = json.loads(response.text)['error']
  12. except (JSONDecodeError, KeyError):
  13. self.detail = response.text