Skip to content
This repository has been archived by the owner on Sep 22, 2024. It is now read-only.

Commit

Permalink
Merge pull request #50 from megahomyak/master
Browse files Browse the repository at this point in the history
Handling of "401 Unauthorized" in `.logout()`
  • Loading branch information
megahomyak committed Mar 10, 2022
2 parents 17612d5 + 3070d62 commit 972c43d
Showing 1 changed file with 14 additions and 5 deletions.
19 changes: 14 additions & 5 deletions netschoolapi/netschoolapi.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,11 +257,20 @@ async def school(self, requests_timeout: int = None):
return data.School(**school)

async def logout(self, requests_timeout: int = None):
await self._wrapped_client.request(
requests_timeout,
'auth/logout',
method="POST",
)
try:
await self._wrapped_client.request(
requests_timeout,
'auth/logout',
method="POST",
)
except httpx.HTTPStatusError as http_status_error:
if http_status_error.response.status_code == httpx.codes.UNAUTHORIZED:
# Session is dead => we are logged out already
# OR
# We are logged out already
pass
else:
raise http_status_error

async def full_logout(self, requests_timeout: int = None):
await self.logout(requests_timeout)
Expand Down

0 comments on commit 972c43d

Please sign in to comment.