mirror of
https://github.com/MODSetter/SurfSense.git
synced 2026-04-26 09:16:22 +02:00
refactor(desktop): extract error handling into modules/errors.ts
This commit is contained in:
parent
e7b5b37404
commit
dff3440f72
2 changed files with 36 additions and 30 deletions
33
surfsense_desktop/src/modules/errors.ts
Normal file
33
surfsense_desktop/src/modules/errors.ts
Normal 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);
|
||||
});
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue