diff --git a/sinch/core/exceptions.py b/sinch/core/exceptions.py index 76b44b0..d1de78b 100644 --- a/sinch/core/exceptions.py +++ b/sinch/core/exceptions.py @@ -1,8 +1,9 @@ +from typing import Union from sinch.core.models.http_response import HTTPResponse class SinchException(Exception): - def __init__(self, message: str, response: HTTPResponse, is_from_server: bool): + def __init__(self, message: str, response: Union[HTTPResponse, None], is_from_server: bool): self.is_from_server = is_from_server self.response_status_code = response.status_code if response else None self.http_response = response diff --git a/sinch/core/token_manager.py b/sinch/core/token_manager.py index 3766749..c5bd529 100644 --- a/sinch/core/token_manager.py +++ b/sinch/core/token_manager.py @@ -1,12 +1,15 @@ from enum import Enum from abc import ABC, abstractmethod -from typing import Optional +from typing import Optional, TYPE_CHECKING from sinch.domains.authentication.models.authentication import OAuthToken from sinch.domains.authentication.endpoints.oauth import OAuthEndpoint from sinch.core.exceptions import ValidationException from sinch.core.models.http_response import HTTPResponse +if TYPE_CHECKING: + from sinch.core.clients.sinch_client_base import ClientBase + class TokenState(Enum): VALID = "VALID" @@ -15,7 +18,7 @@ class TokenState(Enum): class TokenManagerBase(ABC): - def __init__(self, sinch): + def __init__(self, sinch: 'ClientBase') -> None: self.sinch = sinch self.token: Optional[OAuthToken] = None self.token_state = TokenState.INVALID @@ -24,11 +27,11 @@ def __init__(self, sinch): def get_auth_token(self) -> Optional[OAuthToken]: pass - def invalidate_expired_token(self): + def invalidate_expired_token(self) -> None: self.token = None self.token_state = TokenState.EXPIRED - def handle_invalid_token(self, http_response: HTTPResponse): + def handle_invalid_token(self, http_response: HTTPResponse) -> None: if http_response.headers.get("www-authenticate") and "expired" in http_response.headers["www-authenticate"]: self.invalidate_expired_token()