Handle 401 auth expiry and float playground errors
This commit is contained in:
+18
-2
@@ -50,6 +50,7 @@ import {
|
||||
deletePlatform,
|
||||
deleteTenant,
|
||||
deleteUserGroup,
|
||||
GatewayApiError,
|
||||
getHealth,
|
||||
listFileStorageChannels,
|
||||
getFileStorageSettings,
|
||||
@@ -271,7 +272,8 @@ export function App() {
|
||||
loadedDataKeysRef.current.add('modelRateLimits');
|
||||
loadedDataKeysRef.current.add('platforms');
|
||||
})
|
||||
.catch(() => {
|
||||
.catch((err) => {
|
||||
if (handleAuthExpired(err, token)) return;
|
||||
loadedDataKeysRef.current.delete('modelRateLimits');
|
||||
loadedDataKeysRef.current.delete('platforms');
|
||||
});
|
||||
@@ -370,6 +372,7 @@ export function App() {
|
||||
requestKeys.forEach((key) => loadedDataKeysRef.current.add(key));
|
||||
setState('ready');
|
||||
} catch (err) {
|
||||
if (handleAuthExpired(err, nextToken)) return;
|
||||
setState('error');
|
||||
setError(err instanceof Error ? err.message : '加载失败');
|
||||
} finally {
|
||||
@@ -925,7 +928,7 @@ export function App() {
|
||||
}
|
||||
}
|
||||
|
||||
function signOut() {
|
||||
function resetAuthenticatedSession() {
|
||||
persistAccessToken('');
|
||||
setToken('');
|
||||
loadedDataKeysRef.current = new Set(health ? ['health'] : []);
|
||||
@@ -962,6 +965,19 @@ export function App() {
|
||||
setWalletTransactionTotal(0);
|
||||
setWorkspaceTransactionQuery(defaultWorkspaceTransactionQuery());
|
||||
setCoreMessage('');
|
||||
}
|
||||
|
||||
function handleAuthExpired(err: unknown, failedToken: string) {
|
||||
if (!failedToken || !(err instanceof GatewayApiError) || err.details.status !== 401) return false;
|
||||
resetAuthenticatedSession();
|
||||
setError('');
|
||||
setAuthMode('login');
|
||||
navigatePath(pathForWorkspaceSection('overview'));
|
||||
return true;
|
||||
}
|
||||
|
||||
function signOut() {
|
||||
resetAuthenticatedSession();
|
||||
navigatePath('/');
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user