whereis-client/src/exceptions.py
2024-12-18 11:30:31 +01:00

24 lines
627 B
Python

from requests import Response
__all__ = ["WhereIsException", "UnauthorizedException"]
class WhereIsException(Exception):
"""Handle all WhereIs API errors."""
def __init__(self, url: str, response: Response):
self.url = url
try:
self.content = response.json()
except Exception:
self.content = response.content.decode()
super().__init__(self.content)
self.error_code = response.status_code
def __str__(self):
return f"error calling: {self.url} - {self.error_code} - {self.content}"
class UnauthorizedException(WhereIsException):
pass