mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 04:11:10 -05:00
Fix OpenRouter usage with better error handling
This commit is contained in:
@@ -54,6 +54,11 @@ export class OpenRouterHandler implements ApiHandler {
|
||||
tool_choice: "auto",
|
||||
})
|
||||
|
||||
const errorMessage = (completion as any).error?.message // openrouter returns an error object instead of the openai sdk throwing an error
|
||||
if (errorMessage) {
|
||||
throw new Error(errorMessage)
|
||||
}
|
||||
|
||||
// Convert OpenAI response to Anthropic format
|
||||
const openAiMessage = completion.choices[0].message
|
||||
const anthropicMessage: Anthropic.Messages.Message = {
|
||||
@@ -246,7 +251,8 @@ export class OpenRouterHandler implements ApiHandler {
|
||||
openAiMessages.push({
|
||||
role: "assistant",
|
||||
content,
|
||||
tool_calls,
|
||||
// Cannot be an empty array. API expects an array with minimum length 1, and will respond with an error if it's empty
|
||||
tool_calls: tool_calls.length > 0 ? tool_calls : undefined,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
@@ -395,6 +395,12 @@ const ChatView = ({
|
||||
case "api_req_finished": // combineApiRequests removes this from modifiedMessages anyways
|
||||
case "api_req_retried": // this message is used to update the latest api_req_started that the request was retried
|
||||
return false
|
||||
case "text":
|
||||
// Sometimes Claude returns an empty text message, we don't want to render these. (We also use a say text for user messages, so in case they just sent images we still render that)
|
||||
if ((message.text ?? "") === "" && (message.images?.length ?? 0) === 0) {
|
||||
return false
|
||||
}
|
||||
break
|
||||
}
|
||||
return true
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user