refactor(desktop): extract error handling into modules/errors.ts

This commit is contained in:
CREDO23 2026-03-20 19:44:48 +02:00
parent e7b5b37404
commit dff3440f72
2 changed files with 36 additions and 30 deletions

View file

@ -0,0 +1,33 @@
import { app, clipboard, dialog } from 'electron';
export function showErrorDialog(title: string, error: unknown): void {
const err = error instanceof Error ? error : new Error(String(error));
console.error(`${title}:`, err);
if (app.isReady()) {
const detail = err.stack || err.message;
const buttonIndex = dialog.showMessageBoxSync({
type: 'error',
buttons: ['OK', process.platform === 'darwin' ? 'Copy Error' : 'Copy error'],
defaultId: 0,
noLink: true,
message: title,
detail,
});
if (buttonIndex === 1) {
clipboard.writeText(`${title}\n${detail}`);
}
} else {
dialog.showErrorBox(title, err.stack || err.message);
}
}
export function registerGlobalErrorHandlers(): void {
process.on('uncaughtException', (error) => {
showErrorDialog('Unhandled Error', error);
});
process.on('unhandledRejection', (reason) => {
showErrorDialog('Unhandled Promise Rejection', reason);
});
}