diff --git a/apps/ai-game-creator-shell/src/services/errorReporting.ts b/apps/ai-game-creator-shell/src/services/errorReporting.ts index bf828e26e..3592c9fd9 100644 --- a/apps/ai-game-creator-shell/src/services/errorReporting.ts +++ b/apps/ai-game-creator-shell/src/services/errorReporting.ts @@ -17,12 +17,33 @@ export type DiagnosticLogFile = { name: string; content: string }; type WebviewLogLevel = 'debug' | 'info' | 'warn' | 'error' | 'log'; -export const OPEN_ERROR_REPORT_EVENT = 'agc-open-error-report'; - const pending = new Map(); const listeners = new Set<() => void>(); const MAX_EVENTS = 100; +export function shouldCaptureClientError(error: unknown) { + if (!error || typeof error !== 'object') return true; + const candidate = error as { status?: unknown; networkError?: unknown }; + if (candidate.networkError === true) return true; + if (typeof candidate.status === 'number') { + return candidate.status === 408 || candidate.status >= 500; + } + return true; +} + +export async function invokeDiagnostic( + invokeFn: (command: string, args?: Record) => Promise, + command: string, + args?: Record, +) { + try { + return await invokeFn(command, args); + } catch (error) { + void captureClientError(error, { source: 'tauri', action: command }); + throw error; + } +} + function notify() { listeners.forEach((listener) => listener()); }