Skip to content

Commit

Permalink
Merge branch 'main' of github.com:zhulik/aiotractive
Browse files Browse the repository at this point in the history
  • Loading branch information
zhulik committed Aug 20, 2021
2 parents 2784a11 + af7318f commit f6a9043
Showing 1 changed file with 12 additions and 16 deletions.
28 changes: 12 additions & 16 deletions aiotractive/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -103,22 +103,18 @@ async def authenticate(self):
headers=self.base_headers(),
timeout=self._timeout,
) as response:
try:
response.raise_for_status()
if "Content-Type" in response.headers and "application/json" in response.headers["Content-Type"]:
self._user_credentials = await response.json()
self._auth_headers = {
"x-tractive-user": self._user_credentials["user_id"],
"authorization": f"Bearer {self._user_credentials['access_token']}",
}
return self._user_credentials
except ClientResponseError as error:
if error.status in [401, 403]:
raise UnauthorizedError from error
except Exception as error:
raise TractiveError from error
except TractiveError as error:
raise error
response.raise_for_status()
if "Content-Type" in response.headers and "application/json" in response.headers["Content-Type"]:
self._user_credentials = await response.json()
self._auth_headers = {
"x-tractive-user": self._user_credentials["user_id"],
"authorization": f"Bearer {self._user_credentials['access_token']}",
}
return self._user_credentials
except ClientResponseError as error:
if error.status in [401, 403]:
raise UnauthorizedError from error
raise TractiveError from error
except Exception as error:
raise TractiveError from error

Expand Down

0 comments on commit f6a9043

Please sign in to comment.