Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 15 additions & 1 deletion src/components/InsightsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -409,10 +409,24 @@ export class InsightsPanel extends Panel {
this.renderInsights(importantClusters, sentiments, worldBrief);
} catch (error) {
console.error('[InsightsPanel] Error:', error);
this.setContent('<div class="insights-error">Analysis failed - retrying...</div>');
const reason = InsightsPanel.classifyError(error);
this.setContent(`<div class="insights-error">Analysis failed (${reason}) - retrying...</div>`);
}
}

/** Classify an error into a short user-facing category string. */
private static classifyError(err: unknown): string {
if (err instanceof DOMException && err.name === 'AbortError') return 'request cancelled';
if (err instanceof TypeError && /fetch|network/i.test(err.message)) return 'network error';
if (err instanceof Error) {
const msg = err.message.toLowerCase();
if (msg.includes('timeout') || msg.includes('timed out')) return 'timeout';
if (msg.includes('rate') || msg.includes('429') || msg.includes('quota')) return 'rate limited';
if (msg.includes('5') && msg.includes('00')) return 'server error';
}
return 'unexpected error';
}

private renderInsights(
clusters: ClusteredEvent[],
sentiments: Array<{ label: string; score: number }> | null,
Expand Down
23 changes: 20 additions & 3 deletions src/components/NewsPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,11 +166,14 @@ export class NewsPanel extends Panel {
this.setCachedSummary(cacheKey, result.summary);
this.showSummary(result.summary);
} else {
this.summaryContainer.innerHTML = '<div class="panel-summary-error">Could not generate summary</div>';
this.summaryContainer.innerHTML = '<div class="panel-summary-error">Summary unavailable (no providers responded)</div>';
console.warn('[NewsPanel] generateSummary returned null — all providers exhausted');
setTimeout(() => this.hideSummary(), 3000);
}
} catch {
this.summaryContainer.innerHTML = '<div class="panel-summary-error">Summary failed</div>';
} catch (err) {
const reason = NewsPanel.classifyError(err);
this.summaryContainer.innerHTML = `<div class="panel-summary-error">Summary failed (${reason})</div>`;
console.warn('[NewsPanel] Summary error:', err);
setTimeout(() => this.hideSummary(), 3000);
} finally {
this.isSummarizing = false;
Expand Down Expand Up @@ -230,6 +233,20 @@ export class NewsPanel extends Panel {
this.summaryContainer.innerHTML = '';
}

/** Classify an error into a short user-facing category string. */
private static classifyError(err: unknown): string {
if (err instanceof DOMException && err.name === 'AbortError') return 'request cancelled';
if (err instanceof TypeError && /fetch|network/i.test(err.message)) return 'network error';
if (err instanceof Error) {
const msg = err.message.toLowerCase();
if (msg.includes('timeout') || msg.includes('timed out')) return 'timeout';
if (msg.includes('rate') || msg.includes('429') || msg.includes('quota')) return 'rate limited';
if (msg.includes('401') || msg.includes('403') || msg.includes('unauthorized')) return 'auth error';
if (msg.includes('5') && msg.includes('00')) return 'server error';
}
return 'unexpected error';
}

private getHeadlineSignature(): string {
return JSON.stringify(this.currentHeadlines.slice(0, 5).sort());
}
Expand Down
8 changes: 6 additions & 2 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,12 @@ if (!('__TAURI_INTERNALS__' in window) && !('__TAURI__' in window) && 'serviceWo
console.log('[PWA] Service worker registered');
setInterval(async () => {
if (!navigator.onLine) return;
try { await registration.update(); } catch {}
try { await registration.update(); } catch (updateErr) {
console.warn('[PWA] Service worker update check failed:', updateErr);
}
}, 60 * 60 * 1000);
})
.catch(() => {});
.catch((error) => {
console.warn('[PWA] Service worker registration failed:', error);
});
}