mirror of
https://github.com/router-for-me/Cli-Proxy-API-Management-Center.git
synced 2026-06-16 21:03:58 +08:00
fix(usage): propagate loadUsageStats errors
This commit is contained in:
@@ -19,7 +19,7 @@ export const useProviderStats = () => {
|
||||
}, [loadUsageStats]);
|
||||
|
||||
useInterval(() => {
|
||||
void refreshKeyStats();
|
||||
void refreshKeyStats().catch(() => {});
|
||||
}, 240_000);
|
||||
|
||||
return { keyStats, usageDetails, loadKeyStats, refreshKeyStats, isLoading };
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -113,7 +113,7 @@ export function AiProvidersPage() {
|
||||
if (hasMounted.current) return;
|
||||
hasMounted.current = true;
|
||||
loadConfigs();
|
||||
loadKeyStats();
|
||||
void loadKeyStats().catch(() => {});
|
||||
}, [loadConfigs, loadKeyStats]);
|
||||
|
||||
useEffect(() => {
|
||||
|
||||
@@ -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
|
||||
);
|
||||
|
||||
@@ -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')}
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user