R61 A1-A6:Auth token refresh 主动续期
这个提交包含在:
+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);
|
||||
|
||||
在新工单中引用
屏蔽一个用户