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

error handling for 429 too many req #19

Merged
merged 1 commit into from
Mar 2, 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
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
Loading