File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -179,6 +179,14 @@ class Forbidden(TeslaFleetError):
179179 key = "Unauthorized missing scopes"
180180
181181
182+ class InvalidScope (TeslaFleetError ):
183+ """The requested scopes are not granted."""
184+
185+ message = "The requested scopes are not granted."
186+ status = 403
187+ key = "invalid_scope"
188+
189+
182190class UnsupportedVehicle (TeslaFleetError ):
183191 """The vehicle is unsupported."""
184192
@@ -1079,8 +1087,9 @@ async def raise_for_status(resp: aiohttp.ClientResponse) -> None:
10791087 raise exception (data )
10801088 raise PaymentRequired (data )
10811089 elif resp .status == 403 :
1082- if error == UnsupportedVehicle .key :
1083- raise UnsupportedVehicle (data )
1090+ for exception in [InvalidScope , UnsupportedVehicle ]:
1091+ if error == exception .key :
1092+ raise exception (data )
10841093 raise Forbidden (data )
10851094 elif resp .status == 404 :
10861095 raise NotFound (data )
Original file line number Diff line number Diff line change @@ -219,11 +219,10 @@ async def partner_login(
219219 headers = {"Content-Type" : "application/x-www-form-urlencoded" },
220220 data = data ,
221221 ) as resp :
222- if resp .ok :
223- token_data = await resp .json ()
224- # Set the access token for subsequent API calls
225- self ._access_token = token_data ["access_token" ]
226- return token_data
227- else :
228- error_data = await resp .json ()
229- raise ValueError (f"Partner login failed: { error_data } " )
222+ if not resp .ok :
223+ await raise_for_status (resp )
224+
225+ token_data = await resp .json ()
226+ # Set the access token for subsequent API calls
227+ self ._access_token = token_data ["access_token" ]
228+ return token_data
You can’t perform that action at this time.
0 commit comments