Skip to content

Commit 9f19276

Browse files
authored
fix: handle mistral sdk api errors (RooCodeInc#3698)
1 parent 8356e05 commit 9f19276

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed

.changeset/slimy-bees-fail.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"claude-dev": patch
3+
---
4+
5+
Handle Mistral SDK API errors

src/api/providers/mistral.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,23 @@ export class MistralHandler implements ApiHandler {
1919

2020
@withRetry()
2121
async *createMessage(systemPrompt: string, messages: Anthropic.Messages.MessageParam[]): ApiStream {
22-
const stream = await this.client.chat.stream({
23-
model: this.getModel().id,
24-
// max_completion_tokens: this.getModel().info.maxTokens,
25-
temperature: 0,
26-
messages: [{ role: "system", content: systemPrompt }, ...convertToMistralMessages(messages)],
27-
stream: true,
28-
})
22+
const stream = await this.client.chat
23+
.stream({
24+
model: this.getModel().id,
25+
// max_completion_tokens: this.getModel().info.maxTokens,
26+
temperature: 0,
27+
messages: [{ role: "system", content: systemPrompt }, ...convertToMistralMessages(messages)],
28+
stream: true,
29+
})
30+
.catch((err) => {
31+
// The Mistal SDK uses statusCode instead of status
32+
// However, if they introduce status for something, I don't want to override it
33+
if ("statusCode" in err && !("status" in err)) {
34+
err.status = err.statusCode
35+
}
36+
37+
throw err
38+
})
2939

3040
for await (const chunk of stream) {
3141
const delta = chunk.data.choices[0]?.delta

0 commit comments

Comments
 (0)