v1.5.5 use rt and at

This commit is contained in:
lanqian528 2024-10-26 03:11:22 +08:00
parent 2388d437cc
commit cdadb258bf
2 changed files with 5 additions and 4 deletions

View File

@ -59,6 +59,7 @@ else:
with open(TOKENS_FILE, "w", encoding="utf-8") as f:
pass
if os.path.exists(ERROR_TOKENS_FILE):
with open(ERROR_TOKENS_FILE, "r", encoding="utf-8") as f:
for line in f:

View File

@ -45,14 +45,14 @@ async def chat_refresh(refresh_token):
access_token = r.json()['access_token']
return access_token
else:
if "Unknown or invalid refresh token." in r.text:
with open(globals.ERROR_TOKENS_FILE, "a", encoding="utf-8") as f:
f.write(refresh_token + "\n")
if "invalid_grant" in r.text or "access_denied" in r.text:
if refresh_token not in globals.error_token_list:
globals.error_token_list.append(refresh_token)
with open(globals.ERROR_TOKENS_FILE, "a", encoding="utf-8") as f:
f.write(refresh_token + "\n")
raise Exception(r.text)
else:
raise Exception(r.text[:100])
raise Exception(r.text[:300])
except Exception as e:
logger.error(f"Failed to refresh access_token `{refresh_token}`: {str(e)}")
raise HTTPException(status_code=500, detail=f"Failed to refresh access_token.")