fix(usage): propagate loadUsageStats errors

This commit is contained in:
Supra4E8C
2026-02-22 13:13:56 +08:00
Unverified
parent ecaaa397a3
commit 243eaf214c
6 changed files with 18 additions and 8 deletions
@@ -19,7 +19,7 @@ export const useProviderStats = () => {
}, [loadUsageStats]);
useInterval(() => {
void refreshKeyStats();
void refreshKeyStats().catch(() => {});
}, 240_000);
return { keyStats, usageDetails, loadKeyStats, refreshKeyStats, isLoading };
+10 -2
View File
@@ -49,7 +49,7 @@ export function useUsageData(): UseUsageDataReturn {
}, [loadUsageStats]);
useEffect(() => {
void loadUsageStats({ staleTimeMs: USAGE_STATS_STALE_TIME_MS });
void loadUsageStats({ staleTimeMs: USAGE_STATS_STALE_TIME_MS }).catch(() => {});
setModelPrices(loadModelPrices());
}, [loadUsageStats]);
@@ -109,7 +109,15 @@ export function useUsageData(): UseUsageDataReturn {
}),
'success'
);
await loadUsageStats({ force: true, staleTimeMs: USAGE_STATS_STALE_TIME_MS });
try {
await loadUsageStats({ force: true, staleTimeMs: USAGE_STATS_STALE_TIME_MS });
} catch (err: unknown) {
const message = err instanceof Error ? err.message : '';
showNotification(
`${t('notification.refresh_failed')}${message ? `: ${message}` : ''}`,
'error'
);
}
} catch (err: unknown) {
const message = err instanceof Error ? err.message : '';
showNotification(
+1 -1
View File
@@ -113,7 +113,7 @@ export function AiProvidersPage() {
if (hasMounted.current) return;
hasMounted.current = true;
loadConfigs();
loadKeyStats();
void loadKeyStats().catch(() => {});
}, [loadConfigs, loadKeyStats]);
useEffect(() => {
+2 -2
View File
@@ -212,14 +212,14 @@ export function AuthFilesPage() {
useEffect(() => {
if (!isCurrentLayer) return;
loadFiles();
loadKeyStats();
void loadKeyStats().catch(() => {});
loadExcluded();
loadModelAlias();
}, [isCurrentLayer, loadFiles, loadKeyStats, loadExcluded, loadModelAlias]);
useInterval(
() => {
void refreshKeyStats();
void refreshKeyStats().catch(() => {});
},
isCurrentLayer ? 240_000 : null
);
+1 -1
View File
@@ -266,7 +266,7 @@ export function UsagePage() {
<Button
variant="secondary"
size="sm"
onClick={loadUsage}
onClick={() => void loadUsage().catch(() => {})}
disabled={loading || exporting || importing}
>
{loading ? t('common.loading') : t('usage_stats.refresh')}
+3 -1
View File
@@ -109,11 +109,13 @@ export const useUsageStatsStore = create<UsageStatsState>((set, get) => ({
});
} catch (error: unknown) {
if (requestId !== usageRequestToken) return;
const message = getErrorMessage(error);
set({
loading: false,
error: getErrorMessage(error),
error: message,
scopeKey
});
throw new Error(message);
} finally {
if (inFlightUsageRequest?.id === requestId) {
inFlightUsageRequest = null;