fix(api): handle ZodError in processError and formatErrorMessage

Add explicit handling of ZodError in processError to return the error directly and in formatErrorMessage to use formatZodError for better error reporting
This commit is contained in:
icarus 2025-09-18 20:40:30 +08:00
parent ab90eb2aab
commit 7632efda88
2 changed files with 7 additions and 1 deletions

View File

@ -16,6 +16,7 @@ import {
UpdateAgentResponseSchema
} from '@types'
import { Axios, AxiosRequestConfig, isAxiosError } from 'axios'
import { ZodError } from 'zod'
type ApiVersion = 'v1'
@ -29,6 +30,8 @@ const processError = (error: unknown, fallbackMessage: string) => {
if (result.success) {
return new Error(formatAgentServerError(result.data), { cause: error })
}
} else if (error instanceof ZodError) {
return error
}
return new Error(fallbackMessage, { cause: error })
}

View File

@ -9,7 +9,7 @@ import {
} from '@renderer/types/error'
import { InvalidToolInputError, NoSuchToolError } from 'ai'
import { t } from 'i18next'
import { z } from 'zod'
import { z, ZodError } from 'zod'
import { parseJSON } from './json'
import { safeSerialize } from './serialize'
@ -44,6 +44,9 @@ export function getErrorDetails(err: any, seen = new WeakSet()): any {
}
export function formatErrorMessage(error: unknown): string {
if (error instanceof ZodError) {
return formatZodError(error)
}
const detailedError = getErrorDetails(error)
delete detailedError?.headers
delete detailedError?.stack