feat: enhance authentication handling and UI feedback in SurfSense plugin

- Introduced an authentication block mechanism to prevent repeated invalid token submissions.
- Updated notification logic to provide clearer feedback on API token status.
- Refactored status visuals for better clarity and consistency in the user interface.
- Improved connection handling in the sync engine to ensure robust error management.
This commit is contained in:
Anish Sarkar 2026-04-25 01:07:02 +05:30
parent e84dc87c5b
commit 1c18735d38
7 changed files with 42 additions and 49 deletions

View file

@ -75,6 +75,7 @@ export class SurfSenseSettingTab extends PluginSettingTab {
}
this.plugin.settings.apiToken = next;
await this.plugin.saveSettings();
this.plugin.api.resetAuthBlock();
});
})
.addButton((btn) =>
@ -299,7 +300,7 @@ export class SurfSenseSettingTab extends PluginSettingTab {
const kind = this.plugin.lastStatus.kind;
if (kind === "auth-error") {
return { icon: "lock", label: "Token invalid or expired", tone: "err" };
return { icon: "lock", label: "API token invalid or expired", tone: "err" };
}
if (kind === "error") {
return { icon: "alert-circle", label: "Connection error", tone: "err" };
@ -381,10 +382,7 @@ export class SurfSenseSettingTab extends PluginSettingTab {
}
private handleApiError(err: unknown): void {
if (err instanceof AuthError) {
new Notice(`SurfSense: ${err.message}`);
return;
}
if (err instanceof AuthError) return;
new Notice(
`SurfSense: request failed — ${(err as Error).message ?? "unknown error"}`,
);