mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-07 05:39:05 +08:00
fix: use shouldThrow param in checkApi instead of adding error property to CompletionsResult (#7457)
* Revert "refactor(middleware): Add error property to CompletionResult and handle errors when checking API (#7407)"
This reverts commit 50d6f1f831.
* fix: use shouldThrow param in checkApi
This commit is contained in:
parent
355d2aebb4
commit
2350919f36
@ -25,7 +25,7 @@ export const ErrorHandlerMiddleware =
|
||||
// 尝试执行下一个中间件
|
||||
return await next(ctx, params)
|
||||
} catch (error: any) {
|
||||
console.error('ErrorHandlerMiddleware_error', error)
|
||||
console.log('ErrorHandlerMiddleware_error', error)
|
||||
// 1. 使用通用的工具函数将错误解析为标准格式
|
||||
const errorChunk = createErrorChunk(error)
|
||||
// 2. 调用从外部传入的 onError 回调
|
||||
@ -50,7 +50,6 @@ export const ErrorHandlerMiddleware =
|
||||
rawOutput: undefined,
|
||||
stream: errorStream, // 将包含错误的流传递下去
|
||||
controller: undefined,
|
||||
error: typeof error?.message === 'string' ? error.message : 'unknown error',
|
||||
getText: () => '' // 错误情况下没有文本结果
|
||||
}
|
||||
}
|
||||
|
||||
@ -62,7 +62,7 @@ export interface CompletionsResult {
|
||||
rawOutput?: SdkRawOutput
|
||||
stream?: ReadableStream<SdkRawChunk> | ReadableStream<Chunk> | AsyncIterable<Chunk>
|
||||
controller?: AbortController
|
||||
error?: string
|
||||
|
||||
getText: () => string
|
||||
}
|
||||
|
||||
|
||||
@ -590,14 +590,12 @@ export async function checkApi(provider: Provider, model: Model): Promise<void>
|
||||
callType: 'check',
|
||||
messages: 'hi',
|
||||
assistant,
|
||||
streamOutput: true
|
||||
streamOutput: true,
|
||||
shouldThrow: true
|
||||
}
|
||||
|
||||
// Try streaming check first
|
||||
const result = await ai.completions(params)
|
||||
if (result.error) {
|
||||
throw new Error(result.error)
|
||||
}
|
||||
if (!result.getText()) {
|
||||
throw new Error('No response received')
|
||||
}
|
||||
@ -608,12 +606,10 @@ export async function checkApi(provider: Provider, model: Model): Promise<void>
|
||||
callType: 'check',
|
||||
messages: 'hi',
|
||||
assistant,
|
||||
streamOutput: false
|
||||
streamOutput: false,
|
||||
shouldThrow: true
|
||||
}
|
||||
const result = await ai.completions(params)
|
||||
if (result.error) {
|
||||
throw new Error(result.error)
|
||||
}
|
||||
if (!result.getText()) {
|
||||
throw new Error('No response received')
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user