Added Notices for error handling with api endpoints

This commit is contained in:
FBarrca 2025-01-09 23:25:26 +01:00
parent 46e7d3c748
commit 9fe45103b9

View file

@ -55,7 +55,7 @@ export class ChatApiManager {
}
} catch (error) {
console.error("Error initializing chat client:", error);
new Notice(`Failed to initialize chat client. ${error}`);
new Notice(`Error initializing chat client: ${error}`);
throw new Error("Failed to initialize chat client.");
}
}
@ -78,6 +78,7 @@ export class ChatApiManager {
return aiMessage.content.toString();
} catch (error) {
console.error("Error calling the chat model:", error);
new Notice(`Error calling the chat model: ${error}`);
throw new Error("Failed to generate response from the chat model.");
}
}
@ -91,6 +92,7 @@ export class ChatApiManager {
private async handleEditorUpdate(systemPrompt: string, userRequest: string): Promise<string> {
try {
const response = await this.callApi(systemPrompt, userRequest);
const markdownView = this.app.workspace.getActiveViewOfType(MarkdownView);
if (!markdownView) return "";
@ -103,6 +105,7 @@ export class ChatApiManager {
return response;
} catch (error) {
console.error("Error processing request:", error);
new Notice(`Error processing request: ${error}`);
throw new Error("Failed to process request.");
}
}
@ -129,7 +132,7 @@ export class ChatApiManager {
const systemPrompt = isCursor ? this.settings.cursorPrompt : this.settings.selectionPrompt;
let userPrompt = ``
let userPrompt = ``;
if (isCursor) {
userPrompt = `
**Task:** ${prompt}