fix(web): 大纲错误透传 FriendlyError, 不再向用户暴露内部 code
This commit is contained in:
@@ -4,20 +4,20 @@ import { useCallback, useState } from "react";
|
||||
|
||||
import { api } from "@/lib/api/client";
|
||||
import { useToast } from "@/components/Toast";
|
||||
import { friendlyFromApiError } from "@/lib/errors/messages";
|
||||
import {
|
||||
friendlyFromApiError,
|
||||
type FriendlyError,
|
||||
} from "@/lib/errors/messages";
|
||||
import type { OutlineChapterView } from "@/lib/api/types";
|
||||
|
||||
export type OutlineStatus = "idle" | "generating" | "ready" | "error";
|
||||
|
||||
export interface OutlineError {
|
||||
code: string;
|
||||
message: string;
|
||||
}
|
||||
|
||||
export interface UseOutline {
|
||||
chapters: OutlineChapterView[];
|
||||
status: OutlineStatus;
|
||||
error: OutlineError | null;
|
||||
// 直接透传 friendlyFromApiError 的结果(含 text + 可选 actionHref/actionLabel),
|
||||
// 不再拍平成固定的内部 code,UI 据 actionHref 是否存在决定显示跳转链接。
|
||||
error: FriendlyError | null;
|
||||
generate: (projectId: string, volume: number) => Promise<void>;
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ export function useOutline(initial: OutlineChapterView[]): UseOutline {
|
||||
const [status, setStatus] = useState<OutlineStatus>(
|
||||
initial.length > 0 ? "ready" : "idle",
|
||||
);
|
||||
const [error, setError] = useState<OutlineError | null>(null);
|
||||
const [error, setError] = useState<FriendlyError | null>(null);
|
||||
const toast = useToast();
|
||||
|
||||
const generate = useCallback<UseOutline["generate"]>(
|
||||
@@ -45,8 +45,9 @@ export function useOutline(initial: OutlineChapterView[]): UseOutline {
|
||||
if (apiError || !data) {
|
||||
// surface 真实错因(如 LLM_UNAVAILABLE→去设置 provider;422→校验文案),
|
||||
// 而非永远的通用「大纲生成失败」(QA #2:原 env.error.code 漏读 422 的 detail 信封)。
|
||||
// 直接透传 friendly(保留 actionHref/actionLabel),不再拍平成固定 OUTLINE_FAILED。
|
||||
const friendly = friendlyFromApiError(apiError);
|
||||
setError({ code: "OUTLINE_FAILED", message: friendly.text });
|
||||
setError(friendly);
|
||||
setStatus("error");
|
||||
toast(friendly.text, "error");
|
||||
return;
|
||||
|
||||
Reference in New Issue
Block a user