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