diff --git a/src/response.ts b/src/response.ts index dcae213..b87426f 100644 --- a/src/response.ts +++ b/src/response.ts @@ -100,6 +100,18 @@ export class FreeSwitchTimeout extends Error { } } +export class FreeSwitchDisconnect extends Error { + public readonly text: string + constructor (text: string) { + super() + this.text = text + } + + toString (): string { + return `FreeSwitchDisconnect: Disconnected while waiting for ${this.text}` + } +} + // List from https://github.com/signalwire/freeswitch/blob/master/src/switch_event.c#L137 type EventName = | 'CUSTOM' @@ -605,6 +617,15 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter { + this.logger.error('FreeSwitchResponse: onceAsync: on_disconnect', { + event, + comment, + ref: this.__ref + }) + cleanup() + reject(new FreeSwitchDisconnect(`(${this.__ref}) ${event} in ${comment}`)) + } let timer: ReturnType | undefined const cleanup = (): void => { this.removeListener(event, on_event) @@ -612,6 +633,7 @@ export class FreeSwitchResponse extends FreeSwitchEventEmitter { this.logger.error('FreeSwitchResponse: onceAsync: on_timeout', {