mirror of
https://github.com/olcubo/obsidian-cubox.git
synced 2026-07-22 05:43:25 +00:00
feat: handle API key errors in sync process
This commit is contained in:
parent
202cb56275
commit
61ad142bec
3 changed files with 17 additions and 2 deletions
|
|
@ -51,6 +51,13 @@ interface ListResponse {
|
|||
data: CuboxArticle[];
|
||||
}
|
||||
|
||||
export class CuboxApiKeyMissingError extends Error {
|
||||
constructor(message = 'Cubox API key is missing or invalid.') {
|
||||
super(message);
|
||||
this.name = 'CuboxApiKeyMissingError';
|
||||
}
|
||||
}
|
||||
|
||||
interface ContentResponse {
|
||||
code: number;
|
||||
message: string;
|
||||
|
|
@ -183,6 +190,10 @@ export class CuboxApi {
|
|||
method: 'POST',
|
||||
body: JSON.stringify(requestBody)
|
||||
}) as ListResponse;
|
||||
|
||||
if (response.code === -1100) {
|
||||
throw new CuboxApiKeyMissingError(response.message || 'API key not found');
|
||||
}
|
||||
|
||||
const articles = response.data ?? [];
|
||||
const hasMore = articles && articles.length >= pageSize;
|
||||
|
|
|
|||
|
|
@ -490,7 +490,7 @@ export class CuboxSyncSettingTab extends PluginSettingTab {
|
|||
textComponent.inputEl.disabled = true;
|
||||
} else {
|
||||
// 已选择域名,更新描述和链接
|
||||
const url = `https://${domain}/my/settings/extensions`;
|
||||
const url = `https://${domain}/web/settings/extensions`;
|
||||
const descEl = this.apiKeySetting.descEl;
|
||||
|
||||
// 清空现有描述
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
import { addIcon, Notice, Plugin, TFile, TFolder } from 'obsidian';
|
||||
import { CuboxApi } from './cuboxApi';
|
||||
import { CuboxApi, CuboxApiKeyMissingError } from './cuboxApi';
|
||||
import { TemplateProcessor } from './templateProcessor';
|
||||
import { formatDateTime } from './utils';
|
||||
import { CuboxSyncSettingTab, CuboxSyncSettings, DEFAULT_SETTINGS } from './cuboxSetting';
|
||||
|
|
@ -211,6 +211,10 @@ export default class CuboxSyncPlugin extends Plugin {
|
|||
new Notice(message);
|
||||
} catch (error) {
|
||||
console.error('同步 Cubox 数据失败:', error);
|
||||
if (error instanceof CuboxApiKeyMissingError) {
|
||||
new Notice('Cubox API Key not found. Please set your API Key in plugin settings and try again.');
|
||||
return;
|
||||
}
|
||||
new Notice('Cubox sync failed. Please check settings or network.');
|
||||
} finally {
|
||||
this.settings.syncing = false;
|
||||
|
|
|
|||
Loading…
Reference in a new issue