fix(design): preserve command outcome certainty
This commit is contained in:
@@ -12,6 +12,7 @@ import {
|
||||
designAssetDownloadPath,
|
||||
type DesignAsset,
|
||||
type DesignAssetSaveResult,
|
||||
type DesignCommandFailureOutcome,
|
||||
type DesignCommandInput,
|
||||
type DesignCommandResult,
|
||||
type DesignDeleteWorkspaceResult,
|
||||
@@ -24,6 +25,7 @@ type ImageWorkspaceEnvelope<T> = {
|
||||
status?: number;
|
||||
code?: string;
|
||||
error?: string;
|
||||
commandOutcome?: DesignCommandFailureOutcome;
|
||||
data?: T;
|
||||
};
|
||||
|
||||
@@ -32,12 +34,19 @@ export const IMAGE_WORKSPACE_CREATE_PROJECT_EVENT = 'niancode:image-workspace:cr
|
||||
export class ImageWorkspaceApiError extends Error {
|
||||
readonly status: number;
|
||||
readonly code: string;
|
||||
readonly commandOutcome?: DesignCommandFailureOutcome;
|
||||
|
||||
constructor(status: number, code: string, message: string) {
|
||||
constructor(
|
||||
status: number,
|
||||
code: string,
|
||||
message: string,
|
||||
commandOutcome?: DesignCommandFailureOutcome,
|
||||
) {
|
||||
super(message);
|
||||
this.name = 'ImageWorkspaceApiError';
|
||||
this.status = status;
|
||||
this.code = code;
|
||||
this.commandOutcome = commandOutcome;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -66,6 +75,11 @@ function getErrorCode(error: unknown, status: number): string {
|
||||
return 'IMAGE_WORKSPACE_REQUEST_FAILED';
|
||||
}
|
||||
|
||||
function getCommandOutcome(error: unknown): DesignCommandFailureOutcome | undefined {
|
||||
const outcome = error instanceof AppError ? error.details?.commandOutcome : undefined;
|
||||
return outcome === 'definitive_failure' || outcome === 'unknown' ? outcome : undefined;
|
||||
}
|
||||
|
||||
async function requestData<T>(path: string, init: RequestInit = {}): Promise<T> {
|
||||
let response: ImageWorkspaceEnvelope<T>;
|
||||
try {
|
||||
@@ -76,6 +90,7 @@ async function requestData<T>(path: string, init: RequestInit = {}): Promise<T>
|
||||
status,
|
||||
getErrorCode(error, status),
|
||||
error instanceof Error ? error.message : IMAGE_WORKSPACE_UNAVAILABLE_MESSAGE,
|
||||
getCommandOutcome(error),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -84,6 +99,7 @@ async function requestData<T>(path: string, init: RequestInit = {}): Promise<T>
|
||||
response.status ?? 502,
|
||||
response.code ?? 'IMAGE_WORKSPACE_REQUEST_FAILED',
|
||||
response.error ?? 'AI 设计请求失败',
|
||||
response.commandOutcome,
|
||||
);
|
||||
}
|
||||
return response.data;
|
||||
|
||||
Reference in New Issue
Block a user