fix: check for listener count before emitting error
This commit is contained in:
parent
33515169ff
commit
dc56deb08a
3 changed files with 17 additions and 4 deletions
|
@ -91,7 +91,10 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram
|
||||||
|
|
||||||
handleError(socket: unknown, error: Error): void {
|
handleError(socket: unknown, error: Error): void {
|
||||||
this.log.error('error: %s', error.stack)
|
this.log.error('error: %s', error.stack)
|
||||||
this.emit('error', error)
|
|
||||||
|
if (this.listenerCount('error') > 0) {
|
||||||
|
this.emit('error', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConnect(socket: Socket): void {
|
handleConnect(socket: Socket): void {
|
||||||
|
@ -109,7 +112,11 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram
|
||||||
this.emit('ready')
|
this.emit('ready')
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => this.emit('error', err))
|
.catch((err) => {
|
||||||
|
if (this.listenerCount('error') > 0) {
|
||||||
|
this.emit('error', err)
|
||||||
|
}
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
async send(bytes: Uint8Array): Promise<void> {
|
async send(bytes: Uint8Array): Promise<void> {
|
||||||
|
|
|
@ -87,7 +87,10 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram
|
||||||
|
|
||||||
handleError(error: unknown): void {
|
handleError(error: unknown): void {
|
||||||
this.log.error('error: %s', error)
|
this.log.error('error: %s', error)
|
||||||
this.emit('error', error)
|
|
||||||
|
if (this.listenerCount('error') > 0) {
|
||||||
|
this.emit('error', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async handleConnect(socket: Deno.TcpConn): Promise<void> {
|
async handleConnect(socket: Deno.TcpConn): Promise<void> {
|
||||||
|
|
|
@ -84,7 +84,10 @@ export abstract class BaseTcpTransport extends EventEmitter implements ITelegram
|
||||||
|
|
||||||
handleError(error: Error): void {
|
handleError(error: Error): void {
|
||||||
this.log.error('error: %s', error.stack)
|
this.log.error('error: %s', error.stack)
|
||||||
this.emit('error', error)
|
|
||||||
|
if (this.listenerCount('error') > 0) {
|
||||||
|
this.emit('error', error)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleConnect(): void {
|
handleConnect(): void {
|
||||||
|
|
Loading…
Reference in a new issue