feat: improve UX for Ollama 404 errors (missing model)

- src/ollama-client.ts: Detect HTTP 404 on /api/chat and throw a descriptive
  ApiError with the model name and the exact ollama pull command needed.

- src/error-handler.ts: For API_ERROR type, return the error message directly
  instead of prefixing with 'API error: ', so the user-friendly 404 message
  is shown cleanly in the Obsidian notice.

- tests/ollama-client.test.ts: Update 404 assertions to match the new
  descriptive error message.
This commit is contained in:
2026-05-19 21:13:08 +02:00
parent 1ed2e39c3d
commit 138890b9d2
4 changed files with 28 additions and 4 deletions
+2 -2
View File
@@ -214,7 +214,7 @@ describe('OllamaClient', () => {
mockFetch.mockResolvedValue({ ok: false, status: 404 });
await expect(client.streamChatAsPromise(mockMessages, mockTools)).rejects.toThrow(
'Ollama API error: 404'
'Model "llama3" not found. Run \`ollama pull llama3\` first.'
);
});
@@ -418,7 +418,7 @@ describe('OllamaClient', () => {
/* consume */
}
})()
).rejects.toThrow('Ollama API error: 404');
).rejects.toThrow('Model "llama3" not found. Run \`ollama pull llama3\` first.');
});
});