fix(product): 透传产品树AppData保存失败

This commit is contained in:
Script Generator
2026-07-03 16:54:38 +08:00
parent 10691522a2
commit 51767579d7
2 changed files with 15 additions and 2 deletions

View File

@@ -0,0 +1,13 @@
import assert from 'node:assert/strict';
import { readFileSync } from 'node:fs';
import { join } from 'node:path';
import test from 'node:test';
test('product store save helper does not swallow AppData save failures', () => {
const source = readFileSync(join(process.cwd(), 'stores/useProductStore.ts'), 'utf8');
assert.match(
source,
/async function saveStoredOverview\(data: ProductOverview\[\]\) \{\s+await saveServerData\('products-overview', data\);\s+\}/,
);
});

View File

@@ -110,7 +110,7 @@ export const useProductStore = create<ProductState>((set, get) => ({
const overview = await api.get<ProductOverview[]>('/products/overview'); const overview = await api.get<ProductOverview[]>('/products/overview');
set({ overview, loading: false, overviewLoaded: true }); set({ overview, loading: false, overviewLoaded: true });
if (shouldPersistRemoteOverview(overview)) { if (shouldPersistRemoteOverview(overview)) {
saveStoredOverview(overview); void saveStoredOverview(overview).catch(() => {});
} }
} catch { } catch {
set({ overview: MOCK_OVERVIEW, error: null, loading: false, overviewLoaded: true }); set({ overview: MOCK_OVERVIEW, error: null, loading: false, overviewLoaded: true });
@@ -328,7 +328,7 @@ export const useProductStore = create<ProductState>((set, get) => ({
})); }));
async function saveStoredOverview(data: ProductOverview[]) { async function saveStoredOverview(data: ProductOverview[]) {
await saveServerData('products-overview', data).catch(() => {}); await saveServerData('products-overview', data);
} }
async function loadStoredOverview(): Promise<ProductOverview[] | null> { async function loadStoredOverview(): Promise<ProductOverview[] | null> {