export function setupProcessHandlers(options?: { exitOnError?: boolean; onError?: (type: 'uncaughtException' | 'unhandledRejection', error: any) => void; }) { const exit = options?.exitOnError ?? true; const onError = options?.onError; process.on('uncaughtException', (err) => { console.error('[🔥 Uncaught Exception]:', err); onError?.('uncaughtException', err); if (exit) process.exit(1); }); process.on('unhandledRejection', (reason, promise) => { console.error('[💥 Unhandled Rejection]:', reason); onError?.('unhandledRejection', reason); if (exit) process.exit(1); }); process.on('SIGTERM', () => { console.log('[📴 SIGTERM]: Graceful shutdown...'); process.exit(0); }); process.on('SIGINT', () => { console.log('[🛑 SIGINT]: Graceful shutdown...'); process.exit(0); }); }