Skip to content

Commit ecbe43e

Browse files
committed
fix: handle errors in tvdb launch hooks, skip auth without key
1 parent 840b40c commit ecbe43e

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

plugins/tvdb.py

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -52,13 +52,18 @@ def authed(self) -> bool:
5252
return self.jwt_token is not None
5353

5454
def set_api_key(self, bot: CloudBot) -> None:
55-
res = cast(
56-
"dict[str, str]",
57-
self._post(
58-
"/login", json={"apikey": bot.config.get_api_key("tvdb")}
59-
),
60-
)
61-
self.set_token(res["token"])
55+
if key := bot.config.get_api_key("tvdb"):
56+
try:
57+
res = cast(
58+
"dict[str, str]",
59+
self._post("/login", json={"apikey": key}),
60+
)
61+
except requests.HTTPError:
62+
self.set_token(None)
63+
else:
64+
self.set_token(res["token"])
65+
else:
66+
self.set_token(None)
6267

6368
def refresh_token(self, bot: CloudBot) -> None:
6469
if self.jwt_token is None:
@@ -75,7 +80,7 @@ def refresh_token(self, bot: CloudBot) -> None:
7580
else:
7681
self.set_token(res["token"])
7782

78-
def set_token(self, token: str) -> None:
83+
def set_token(self, token: str | None) -> None:
7984
self.jwt_token = token
8085
self.refresh_time = datetime.datetime.now() + self.token_lifetime
8186
# Clear header cache

0 commit comments

Comments
 (0)