fix(aiCore): FinalChunkConsumerMiddleware throw error (#8993)

* fix(aiCore): 修复中间件错误处理和日志输出问题

修复FinalChunkConsumerMiddleware中错误无法被ErrorHandlerMiddleware捕获的问题,并优化日志输出格式

* fix: 移除检查API时的冗余日志记录
This commit is contained in:
Phantom 2025-08-09 02:22:09 +08:00 committed by GitHub
parent c97ece946a
commit 6c5088f071
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 12 additions and 3 deletions

View File

@ -123,7 +123,10 @@ export default class AiProvider {
} }
const middlewares = builder.build() const middlewares = builder.build()
logger.silly('middlewares', middlewares) logger.silly(
'middlewares',
middlewares.map((m) => m.name)
)
// 3. Create the wrapped SDK method with middlewares // 3. Create the wrapped SDK method with middlewares
const wrappedCompletionMethod = applyCompletionsMiddlewares(client, client.createCompletions, middlewares) const wrappedCompletionMethod = applyCompletionsMiddlewares(client, client.createCompletions, middlewares)

View File

@ -85,9 +85,15 @@ const FinalChunkConsumerMiddleware: CompletionsMiddleware =
logger.warn(`Received undefined chunk before stream was done.`) logger.warn(`Received undefined chunk before stream was done.`)
} }
} }
} catch (error) { } catch (error: any) {
logger.error(`Error consuming stream:`, error as Error) logger.error(`Error consuming stream:`, error as Error)
throw error // FIXME: 临时解决方案。该中间件的异常无法被 ErrorHandlerMiddleware捕获。
if (params.onError) {
params.onError(error)
}
if (params.shouldThrow) {
throw error
}
} finally { } finally {
if (params.onChunk && !isRecursiveCall) { if (params.onChunk && !isRecursiveCall) {
params.onChunk({ params.onChunk({