From 8c05f88ad2cccd23ffc11c0097e10a3e7e19607f Mon Sep 17 00:00:00 2001 From: Sugawara Date: Sat, 2 Mar 2024 21:58:57 +0900 Subject: [PATCH] error handling for 429 too many req (#19) --- pmemo/api/auth.py | 6 ++++++ pmemo/api/client.py | 5 +++++ 2 files changed, 11 insertions(+) diff --git a/pmemo/api/auth.py b/pmemo/api/auth.py index dd1f59c..f94e817 100644 --- a/pmemo/api/auth.py +++ b/pmemo/api/auth.py @@ -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( @@ -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( @@ -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( diff --git a/pmemo/api/client.py b/pmemo/api/client.py index a80aad0..0e1d55b 100644 --- a/pmemo/api/client.py +++ b/pmemo/api/client.py @@ -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: @@ -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: