fix(whatsapp): reconnect on crypto unhandled rejection
This commit is contained in:
26
src/infra/unhandled-rejections.ts
Normal file
26
src/infra/unhandled-rejections.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
type UnhandledRejectionHandler = (reason: unknown) => boolean;
|
||||
|
||||
const handlers = new Set<UnhandledRejectionHandler>();
|
||||
|
||||
export function registerUnhandledRejectionHandler(
|
||||
handler: UnhandledRejectionHandler,
|
||||
): () => void {
|
||||
handlers.add(handler);
|
||||
return () => {
|
||||
handlers.delete(handler);
|
||||
};
|
||||
}
|
||||
|
||||
export function isUnhandledRejectionHandled(reason: unknown): boolean {
|
||||
for (const handler of handlers) {
|
||||
try {
|
||||
if (handler(reason)) return true;
|
||||
} catch (err) {
|
||||
console.error(
|
||||
"[clawdbot] Unhandled rejection handler failed:",
|
||||
err instanceof Error ? (err.stack ?? err.message) : err,
|
||||
);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
Reference in New Issue
Block a user