From a38a096ba12415821e52b1492f5e4c57f96b86af Mon Sep 17 00:00:00 2001 From: Jesse_Chen Date: Tue, 21 Jul 2026 17:54:27 +0800 Subject: [PATCH] fix: normalize automatic birth-time errors --- .../use-birth-time-automatic-journey-effects.ts | 5 +++-- frontend/tests/birth-time-user-errors.test.ts | 15 +++++++++++++-- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/frontend/src/hooks/use-birth-time-automatic-journey-effects.ts b/frontend/src/hooks/use-birth-time-automatic-journey-effects.ts index 6cb311b4..35b30b07 100644 --- a/frontend/src/hooks/use-birth-time-automatic-journey-effects.ts +++ b/frontend/src/hooks/use-birth-time-automatic-journey-effects.ts @@ -16,6 +16,7 @@ import { } from "@/lib/birth-time-guided-effect-coordinator"; import type { StableActionIdentityRegistry } from "@/lib/birth-time-guided-effect-coordinator"; import { runBirthTimeScoringPoll, scoringPollDelay } from "@/lib/birth-time-guided-polling"; +import { birthTimeUserError } from "@/lib/birth-time-user-error"; type AutomaticEffectsInput = { readonly journey: JourneyClientResponse | null; @@ -82,7 +83,7 @@ export function useBirthTimeAutomaticJourneyEffects(input: AutomaticEffectsInput if (publishCurrentJourney({ expected, current: latest.current, next, publish: onJourney })) latest.current = next; }).catch((caught: unknown) => { if (latest.current?.caseId === expected.caseId && latest.current.turnVersion === expected.turnVersion) { - setError(caught instanceof Error ? caught.message : "暂时无法生成下一题,请重试。"); + setError(birthTimeUserError(caught)); } }); }, [actionRegistry, generationIdentity, generationRequests, generationRun, latest, onJourney, preview, setError]); @@ -114,7 +115,7 @@ export function useBirthTimeAutomaticJourneyEffects(input: AutomaticEffectsInput latest.current = result.turn; if (result.kind === "exhausted") setError("评分仍在进行。你可以稍后继续,或重新检查状态。"); }).catch((caught: unknown) => { - if (!controller.signal.aborted) setError(caught instanceof Error ? caught.message : "暂时无法读取评分进度,请稍后重试。"); + if (!controller.signal.aborted) setError(birthTimeUserError(caught)); }); }); return () => { cancelStart(); controller.abort(); }; diff --git a/frontend/tests/birth-time-user-errors.test.ts b/frontend/tests/birth-time-user-errors.test.ts index fd611a84..56f00bd0 100644 --- a/frontend/tests/birth-time-user-errors.test.ts +++ b/frontend/tests/birth-time-user-errors.test.ts @@ -15,6 +15,17 @@ test("birth-time errors preserve a safe server message", () => { }); test("all guided journey mutations normalize implementation errors", () => { - const source = readFileSync(new URL("../src/hooks/use-birth-time-guided-journey.ts", import.meta.url), "utf8"); - assert.equal((source.match(/setError\(birthTimeUserError\(caught\)\)/g) ?? []).length, 2); + const sources = [ + "../src/hooks/use-birth-time-guided-journey.ts", + "../src/hooks/use-birth-time-automatic-journey-effects.ts", + ].map((path) => readFileSync(new URL(path, import.meta.url), "utf8")); + assert.equal( + sources.reduce( + (count, source) => + count + + (source.match(/setError\(birthTimeUserError\(caught\)\)/g) ?? []).length, + 0, + ), + 3, + ); });