Skip to content

Commit

Permalink
fix: suppress errors when connection is inactive
Browse files Browse the repository at this point in the history
  • Loading branch information
Julusian committed Feb 16, 2022
1 parent 8951f25 commit b7e540d
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
3 changes: 2 additions & 1 deletion src/__mocks__/net.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,10 +53,11 @@ export class Socket extends EventEmitter {
}, 3)
}
public write(buff: Buffer, encoding = 'utf8'): void {
expect(this.expectedWrites).not.toHaveLength(0)
if (this.expectedWrites.length === 0) throw new Error('Got unexpected write')

const w = this.expectedWrites.shift()
if (w) {
// eslint-disable-next-line jest/no-standalone-expect
expect(buff).toEqual(w.call)
this.emit('data', w.response)
}
Expand Down
11 changes: 9 additions & 2 deletions src/hyperdeck.ts
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,12 @@ export class Hyperdeck extends EventEmitter {
.then(() => {
this._logDebug('ping: setting up')
this._pingInterval = setInterval(() => {
if (this.connected) this._performPing().catch((e) => this.emit('error', e))
if (this.connected)
this._performPing().catch((e) => {
if (this._connectionActive) {
this.emit('error', e)
}
})
}, this._pingPeriod)
})
.then(() => c)
Expand All @@ -199,7 +204,9 @@ export class Hyperdeck extends EventEmitter {
.catch((e) => {
this._connected = false
this.socket.destroy()
this.emit('error', 'connection failed', e)
if (this._connectionActive) {
this.emit('error', 'connection failed', e)
}
this._log('connection failed', e)

this._triggerRetryConnection()
Expand Down

0 comments on commit b7e540d

Please sign in to comment.