mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
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:
parent
ab90eb2aab
commit
7632efda88
@ -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 })
|
||||
}
|
||||
|
||||
@ -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
|
||||
|
||||
Loading…
Reference in New Issue
Block a user