Skip to content

Commit

Permalink
feat: add RefreshTokenExpiredError, use aclose (#217)
Browse files Browse the repository at this point in the history
* feat: add `RefreshTokenExpiredError`, use `aclose`

* docs: add breaking change warning for `close()`
  • Loading branch information
NiceAesth authored Feb 9, 2024
1 parent 9f21227 commit f5e8536
Show file tree
Hide file tree
Showing 15 changed files with 130 additions and 27 deletions.
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

0 comments on commit f5e8536

Please sign in to comment.