diff --git a/satellitevu/apis/base.py b/satellitevu/apis/base.py index 6228a5c..3f0ef61 100644 --- a/satellitevu/apis/base.py +++ b/satellitevu/apis/base.py @@ -28,13 +28,18 @@ def make_request(self, *args, **kwargs): response = self.client.request(*args, **kwargs) if response.status == 401: - raise Api401Error("Unauthorized to make this request.") + raise Api401Error( + "Unauthorized to make this request.", response, args, kwargs + ) elif response.status == 403: raise Api403Error( ( "Not permitted to perform this action. " "Please contact Satellite Vu for assistance." - ) + ), + response, + args, + kwargs, ) return response diff --git a/satellitevu/auth/auth.py b/satellitevu/auth/auth.py index 347fbaa..f8d7912 100644 --- a/satellitevu/auth/auth.py +++ b/satellitevu/auth/auth.py @@ -72,17 +72,15 @@ def _auth(self, scopes: Optional[List] = None) -> str: scopes = [] logger.info("Performing client_credential authentication") token_url = urljoin(self.auth_url, "oauth/token") - response = self.client.post( - token_url, - headers={"content-type": "application/x-www-form-urlencoded"}, - data={ - "grant_type": "client_credentials", - "client_id": self.client_id, - "client_secret": self.client_secret, - "audience": self.audience, - "scope": " ".join(scopes), - }, - ) + headers = {"content-type": "application/x-www-form-urlencoded"} + data = { + "grant_type": "client_credentials", + "client_id": self.client_id, + "client_secret": self.client_secret, + "audience": self.audience, + "scope": " ".join(scopes), + } + response = self.client.post(token_url, headers=headers, data=data) if response.status != 200: raise AuthError( @@ -94,5 +92,8 @@ def _auth(self, scopes: Optional[List] = None) -> str: return payload["access_token"] except Exception: raise AuthError( - "Unexpected response body for client_credential flow: " + response.text + "Unexpected response body for client_credential flow: " + response.text, + response, + ["POST", token_url], + {"headers": headers, "data": data}, ) diff --git a/satellitevu/auth/exc.py b/satellitevu/auth/exc.py index a127afd..8f20f8a 100644 --- a/satellitevu/auth/exc.py +++ b/satellitevu/auth/exc.py @@ -1,5 +1,18 @@ +from satellitevu.http.base import ResponseWrapper + + class AuthError(RuntimeError): - pass + def __init__( + self, + message: str, + response: ResponseWrapper | None = None, + request_args: list = [], + request_kwargs: dict = {}, + ): + super().__init__(message) + self.response = response + self.request_args = request_args + self.request_kwargs = request_kwargs class Api401Error(AuthError):