Skip to content
This repository was archived by the owner on May 15, 2026. It is now read-only.

Commit fb0bc26

Browse files
committed
fix(api): add error handling for AI SDK errors in Mistral provider
- Add handleAiSdkError to imports from ../transform/ai-sdk - Wrap stream processing in try/catch block - Handle AI_RetryError, AI_APICallError, etc. with proper error transformation Addresses review comment about missing error handling for AI SDK errors.
1 parent 3efb7ec commit fb0bc26

1 file changed

Lines changed: 20 additions & 10 deletions

File tree

src/api/providers/mistral.ts

Lines changed: 20 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@ import {
1212

1313
import type { ApiHandlerOptions } from "../../shared/api"
1414

15-
import { convertToAiSdkMessages, convertToolsForAiSdk, processAiSdkStreamPart } from "../transform/ai-sdk"
15+
import {
16+
convertToAiSdkMessages,
17+
convertToolsForAiSdk,
18+
processAiSdkStreamPart,
19+
handleAiSdkError,
20+
} from "../transform/ai-sdk"
1621
import { ApiStream, ApiStreamUsageChunk } from "../transform/stream"
1722
import { getModelParams } from "../transform/model-params"
1823

@@ -158,17 +163,22 @@ export class MistralHandler extends BaseProvider implements SingleCompletionHand
158163
// Use streamText for streaming responses
159164
const result = streamText(requestOptions)
160165

161-
// Process the full stream to get all events including reasoning
162-
for await (const part of result.fullStream) {
163-
for (const chunk of processAiSdkStreamPart(part)) {
164-
yield chunk
166+
try {
167+
// Process the full stream to get all events including reasoning
168+
for await (const part of result.fullStream) {
169+
for (const chunk of processAiSdkStreamPart(part)) {
170+
yield chunk
171+
}
165172
}
166-
}
167173

168-
// Yield usage metrics at the end
169-
const usage = await result.usage
170-
if (usage) {
171-
yield this.processUsageMetrics(usage)
174+
// Yield usage metrics at the end
175+
const usage = await result.usage
176+
if (usage) {
177+
yield this.processUsageMetrics(usage)
178+
}
179+
} catch (error) {
180+
// Handle AI SDK errors (AI_RetryError, AI_APICallError, etc.)
181+
throw handleAiSdkError(error, "Mistral")
172182
}
173183
}
174184

0 commit comments

Comments
 (0)