mirror of
https://github.com/khoaliber/khoj.git
synced 2026-03-07 13:23:15 +00:00
Load obsidian plugin even if fail to connect to backend but show warning
- Previously the plugin would not load if cannot connect to Khoj backend - Silently failing to load with no reason provided is not helpful - Load plugin to allow user to fix the Khoj URL in their plugin setting - Show reason for khoj plugin not working. More helpful than failing silently
This commit is contained in:
@@ -13,16 +13,23 @@ export async function configureKhojBackend(setting: KhojSetting) {
|
|||||||
let mdInVault = `${setting.obsidianVaultPath}/**/*.md`;
|
let mdInVault = `${setting.obsidianVaultPath}/**/*.md`;
|
||||||
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
|
let khojConfigUrl = `${setting.khojUrl}/api/config/data`;
|
||||||
|
|
||||||
// Load khoj app config from backend API, Update Markdown config and save
|
// Check if khoj backend is configured, show error if backend is not running
|
||||||
let khoj_configured = await request(khojConfigUrl)
|
let khoj_already_configured = await request(khojConfigUrl)
|
||||||
.then(response => response !== "null");
|
.then(response => {
|
||||||
|
return response !== "null"
|
||||||
|
})
|
||||||
|
.catch(error => {
|
||||||
|
new Notice(`❗️Ensure Khoj backend is running and Khoj URL is pointing to it in the Khoj plugin settings.\n\n${error}`);
|
||||||
|
})
|
||||||
|
// Short-circuit configuring khoj if unable to connect to khoj backend
|
||||||
|
if (khoj_already_configured === null) return;
|
||||||
|
|
||||||
// Get current config if khoj backend configured, else get default config from khoj backend
|
// Get current config if khoj backend configured, else get default config from khoj backend
|
||||||
await request(khoj_configured ? khojConfigUrl : `${khojConfigUrl}/default`)
|
await request(khoj_already_configured ? khojConfigUrl : `${khojConfigUrl}/default`)
|
||||||
.then(response => JSON.parse(response))
|
.then(response => JSON.parse(response))
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// If khoj backend not configured yet
|
// If khoj backend not configured yet
|
||||||
if (!khoj_configured) {
|
if (!khoj_already_configured) {
|
||||||
// Create khoj content-type config with only markdown configured
|
// Create khoj content-type config with only markdown configured
|
||||||
let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`;
|
let khojObsidianPluginPath = `${setting.obsidianVaultPath}/${this.app.vault.configDir}/plugins/khoj/`;
|
||||||
data["content-type"] = {
|
data["content-type"] = {
|
||||||
@@ -70,9 +77,10 @@ export async function configureKhojBackend(setting: KhojSetting) {
|
|||||||
updateKhojBackend(setting.khojUrl, data);
|
updateKhojBackend(setting.khojUrl, data);
|
||||||
console.log(`Khoj: Updated markdown config in khoj backend config:\n${JSON.stringify(data["content-type"]["markdown"])}`)
|
console.log(`Khoj: Updated markdown config in khoj backend config:\n${JSON.stringify(data["content-type"]["markdown"])}`)
|
||||||
}
|
}
|
||||||
|
new Notice(`✅ Successfully Setup Khoj`);
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
new Notice(`Ensure Khoj backend is running and Khoj URL is correct in the Khoj plugin settings.\nError: ${error}`);
|
new Notice(`❗️Failed to configure Khoj backend. Contact developer on Github. \n\nError: ${error}`);
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user