exceptions.py 948 B

1234567891011121314151617181920212223242526272829303132
  1. import json
  2. class WaterCrawlError(Exception):
  3. pass
  4. class WaterCrawlBadRequestError(WaterCrawlError):
  5. def __init__(self, response):
  6. self.status_code = response.status_code
  7. self.response = response
  8. data = response.json()
  9. self.message = data.get("message", "Unknown error occurred")
  10. self.errors = data.get("errors", {})
  11. super().__init__(self.message)
  12. @property
  13. def flat_errors(self):
  14. return json.dumps(self.errors)
  15. def __str__(self):
  16. return f"WaterCrawlBadRequestError: {self.message} \n {self.flat_errors}"
  17. class WaterCrawlPermissionError(WaterCrawlBadRequestError):
  18. def __str__(self):
  19. return f"You are exceeding your WaterCrawl API limits. {self.message}"
  20. class WaterCrawlAuthenticationError(WaterCrawlBadRequestError):
  21. def __str__(self):
  22. return "WaterCrawl API key is invalid or expired. Please check your API key and try again."