fix: 只有确认登录失效才删除已保存凭证
This commit is contained in:
@@ -7,7 +7,7 @@ from datetime import datetime
|
|||||||
|
|
||||||
import httpx
|
import httpx
|
||||||
|
|
||||||
from app.platform.client import NqiClient, NqiError
|
from app.platform.client import NqiAuthError, NqiClient, NqiError
|
||||||
from app.shared.paths import DATA_ROOT
|
from app.shared.paths import DATA_ROOT
|
||||||
|
|
||||||
STORE = DATA_ROOT / "sessions.json"
|
STORE = DATA_ROOT / "sessions.json"
|
||||||
@@ -75,9 +75,9 @@ async def available_accounts() -> list[dict]:
|
|||||||
try:
|
try:
|
||||||
client.import_cookies(item.get("cookies") or [])
|
client.import_cookies(item.get("cookies") or [])
|
||||||
user = await client.current_user()
|
user = await client.current_user()
|
||||||
except NqiError:
|
except NqiAuthError:
|
||||||
continue
|
continue
|
||||||
except (httpx.TimeoutException, httpx.RequestError):
|
except (NqiError, httpx.TimeoutException, httpx.RequestError, TimeoutError):
|
||||||
kept.append(item)
|
kept.append(item)
|
||||||
continue
|
continue
|
||||||
else:
|
else:
|
||||||
@@ -105,12 +105,15 @@ async def resume(login_id: str) -> tuple[NqiClient, dict]:
|
|||||||
try:
|
try:
|
||||||
client.import_cookies(matched.get("cookies") or [])
|
client.import_cookies(matched.get("cookies") or [])
|
||||||
user = await client.current_user()
|
user = await client.current_user()
|
||||||
except NqiError:
|
except NqiAuthError:
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
forget(login_id)
|
forget(login_id)
|
||||||
raise NqiError("这个账号的登录已失效")
|
raise NqiError("这个账号的登录已失效") from None
|
||||||
except (httpx.TimeoutException, httpx.RequestError):
|
except NqiError:
|
||||||
await client.aclose()
|
await client.aclose()
|
||||||
raise NqiError("连接失败,请稍后重试")
|
raise
|
||||||
|
except (httpx.TimeoutException, httpx.RequestError, TimeoutError):
|
||||||
|
await client.aclose()
|
||||||
|
raise NqiError("连接失败,请稍后重试") from None
|
||||||
remember(user, client.export_cookies())
|
remember(user, client.export_cookies())
|
||||||
return client, user
|
return client, user
|
||||||
|
|||||||
Reference in New Issue
Block a user