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