Skip to content

Commit

Permalink
error handling for 429 too many req (#19)
Browse files Browse the repository at this point in the history
  • Loading branch information
Asugawara authored Mar 2, 2024
1 parent 387b048 commit 8c05f88
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
6 changes: 6 additions & 0 deletions pmemo/api/auth.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ def signup(self) -> Tokens:
tokens = res.json()
if res.status_code == requests.codes.ok:
logger.info("Signup Success")
elif res.status_code == requests.codes.too_many_requests:
logger.error("Too many requests")
else:
logger.error("Signup Failed")
return Tokens(
Expand All @@ -48,6 +50,8 @@ def _refresh_token(self, refresh_token: str) -> Tokens:
tokens = res.json()
if res.status_code == requests.codes.ok:
logger.info("Refresh Token Success")
elif res.status_code == requests.codes.too_many_requests:
logger.error("Too many requests")
else:
logger.error("Refresh Token Failed")
return Tokens(
Expand All @@ -66,6 +70,8 @@ def login(self, refresh_token: Optional[str]) -> Tokens:
tokens = res.json()
if res.status_code == requests.codes.ok:
logger.info("Login Success")
elif res.status_code == requests.codes.too_many_requests:
logger.error("Too many requests")
else:
logger.error("Login Failed")
return Tokens(
Expand Down
5 changes: 5 additions & 0 deletions pmemo/api/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ def store_memo(self, file_name: bytes, content: bytes) -> None:
)
if res.status_code == requests.codes.ok:
logger.info("Memo stored successfully: %s", file_name.decode("utf-8"))
elif res.status_code == requests.codes.too_many_requests:
logger.error("Too many requests")
else:
logger.error("Failed to store memo")
if self._tokens.token:
Expand All @@ -39,6 +41,9 @@ def get_memos(self) -> list[str]:
self._config.memos,
headers={"Authorization": f"Bearer {self._tokens.token}"},
)
if res.status_code == requests.codes.too_many_requests:
logger.error("Too many requests")
return []
if res.status_code != requests.codes.ok:
logger.error("Failed to get memos")
if self._tokens.token:
Expand Down

0 comments on commit 8c05f88

Please sign in to comment.