Route a rejecting async listener to sessionError instead of the process

This commit is contained in:
2026-08-27 22:22:51 +02:00
parent 3c6195a938
commit 0e8f298957
7 changed files with 111 additions and 16 deletions
+13 -1
View File
@@ -76,8 +76,20 @@ export class Session extends EventEmitter<SessionEvents> {
}
}
/** The same guard for a listener that rejects rather than throws; captureRejections routes here. */
override [EventEmitter.captureRejectionSymbol](
error: Error,
...args: [event: keyof SessionEvents, ...rest: unknown[]]
): void {
const [event] = args;
this.log.error('session - a listener rejected', { event, message: error.message });
if (event !== 'sessionError') this.emit('sessionError', error);
}
constructor(options: SessionOptions) {
super();
super({ captureRejections: true });
this.log = options.log ?? silentLog;
this.options = options;