Skip to content

Commit 568ed67

Browse files
committed
Fixed error messaging
1 parent fb757c5 commit 568ed67

1 file changed

Lines changed: 23 additions & 18 deletions

File tree

src/api/providers/pearai/pearai.ts

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -116,28 +116,33 @@ export class PearAIHandler extends BaseProvider implements SingleCompletionHandl
116116
}
117117

118118
async *createMessage(systemPrompt: string, messages: any[]): AsyncGenerator<any> {
119-
const generator = this.handler.createMessage(systemPrompt, messages)
120-
let warningMsg = ""
119+
try {
120+
const generator = this.handler.createMessage(systemPrompt, messages)
121+
let warningMsg = ""
121122

122-
for await (const chunk of generator) {
123-
console.dir(chunk)
124-
if (chunk.type === "text" && chunk.metadata?.ui_only) {
125-
warningMsg += chunk.metadata?.content
126-
continue
123+
for await (const chunk of generator) {
124+
console.dir(chunk)
125+
if (chunk.type === "text" && chunk.metadata?.ui_only) {
126+
warningMsg += chunk.metadata?.content ?? ""
127+
continue
128+
}
129+
yield chunk
127130
}
128-
yield chunk
129-
}
130131

131-
if (warningMsg) {
132-
if (warningMsg.includes("pay-as-you-go")) {
133-
vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => {
134-
if (selection === "View Pay-As-You-Go") {
135-
vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go"))
136-
}
137-
})
138-
} else {
139-
vscode.window.showInformationMessage(warningMsg)
132+
if (warningMsg) {
133+
if (warningMsg.includes("pay-as-you-go")) {
134+
vscode.window.showInformationMessage(warningMsg, "View Pay-As-You-Go").then((selection) => {
135+
if (selection === "View Pay-As-You-Go") {
136+
vscode.env.openExternal(vscode.Uri.parse("https://trypear.ai/pay-as-you-go"))
137+
}
138+
})
139+
} else {
140+
vscode.window.showInformationMessage(warningMsg)
141+
}
140142
}
143+
} catch (e) {
144+
const errorMessage = e instanceof Error ? e.message : String(e)
145+
vscode.window.showWarningMessage(`Notice: ${errorMessage}`)
141146
}
142147
}
143148

0 commit comments

Comments
 (0)