Skip to content

Commit 20ba104

Browse files
committed
fix(xai): simplify completePrompt error handling; remove nested try/catch and use handleOpenAIError directly
1 parent d3f020f commit 20ba104

File tree

1 file changed

+6
-15
lines changed

1 file changed

+6
-15
lines changed

src/api/providers/xai.ts

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -112,24 +112,15 @@ export class XAIHandler extends BaseProvider implements SingleCompletionHandler
112112
const { id: modelId, reasoning } = this.getModel()
113113

114114
try {
115-
let response
116-
try {
117-
response = await this.client.chat.completions.create({
118-
model: modelId,
119-
messages: [{ role: "user", content: prompt }],
120-
...(reasoning && reasoning),
121-
})
122-
} catch (error) {
123-
throw handleOpenAIError(error, "xAI")
124-
}
115+
const response = await this.client.chat.completions.create({
116+
model: modelId,
117+
messages: [{ role: "user", content: prompt }],
118+
...(reasoning && reasoning),
119+
})
125120

126121
return response.choices[0]?.message.content || ""
127122
} catch (error) {
128-
if (error instanceof Error) {
129-
throw new Error(`xAI completion error: ${error.message}`)
130-
}
131-
132-
throw error
123+
throw handleOpenAIError(error, "xAI")
133124
}
134125
}
135126
}

0 commit comments

Comments
 (0)