R61 A1-A6:Auth token refresh 主动续期

这个提交包含在:
2026-04-12 16:45:49 +08:00
父节点 7b7a56d7c9
当前提交 dabb03e55b
共修改 5 个文件,包含 213 行新增和 45 行删除
+10 -7
查看文件
@@ -1,4 +1,4 @@
import { ApiError, type ApiErrorBody, type ApiSuccess } from "./types";
import { ApiError, SessionExpiredError, type ApiErrorBody, type ApiSuccess } from "./types";
type AccessTokenGetter = () => string | null;
type RefreshAccessToken = () => Promise<string | null>;
@@ -79,6 +79,13 @@ async function getRefreshedToken(): Promise<string | null> {
return refreshPromise;
}
function throwSessionExpired(): never {
if (clearSession) {
clearSession();
}
throw new SessionExpiredError();
}
async function sendRequest<T>(
path: string,
options: ApiRequestOptions,
@@ -118,9 +125,7 @@ async function sendRequest<T>(
});
}
if (clearSession) {
clearSession();
}
throwSessionExpired();
}
const payload = await safeParseJson(response);
@@ -210,9 +215,7 @@ export async function apiRequestBlob(
});
}
if (clearSession) {
clearSession();
}
throwSessionExpired();
}
const payload = await safeParseJson(response);