Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add RefreshTokenExpiredError, use aclose #217

Merged
merged 3 commits into from
Feb 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ API v1 Example
# regular syntax
client = aiosu.v1.Client("osu api token")
user = await client.get_user(7782553)
await client.close()
await client.aclose()


if __name__ == "__main__":
Expand Down Expand Up @@ -95,7 +95,7 @@ API v2 Example
# regular syntax
client = aiosu.v2.Client(client_secret="secret", client_id=1000, token=token)
user = await client.get_me()
await client.close()
await client.aclose()


if __name__ == "__main__":
Expand Down
13 changes: 12 additions & 1 deletion aiosu/exceptions.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"""
from __future__ import annotations

__all__ = ("APIException",)
__all__ = ("APIException", "InvalidClientRequestedError", "RefreshTokenExpiredError")


class APIException(Exception):
Expand All @@ -20,6 +20,17 @@ def __init__(self, status: int, message: str = "") -> None:
self.status = status


class RefreshTokenExpiredError(Exception):
"""Refresh Token Expired Error

:param message: error message, defaults to ""
:type message: str, optional
"""

def __init__(self, message: str = "") -> None:
super().__init__(message)


class InvalidClientRequestedError(Exception):
"""Invalid Client Requested Error

Expand Down
12 changes: 10 additions & 2 deletions aiosu/v1/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ async def __aexit__(
exc: Optional[BaseException],
traceback: Optional[TracebackType],
) -> None:
await self.close()
await self.aclose()

async def _request(
self,
Expand Down Expand Up @@ -475,8 +475,16 @@ async def get_beatmap_osu(self, beatmap_id: int) -> StringIO:
data = await self._request("GET", url)
return StringIO(data)

async def close(self) -> None:
async def aclose(self) -> None:
"""Closes the client session."""
if self._session:
await self._session.close()
self._session = None

async def close(self) -> None:
"""Closes the client session. (Deprecated)"""
warn(
"close is deprecated, use aclose instead. Will be removed on 2024-03-01",
DeprecationWarning,
)
await self.aclose()
Loading