mirror of
https://github.com/jambonz/jambonz-feature-server.git
synced 2025-12-20 16:50:39 +00:00
catch exceptions from req.cancel() (#1359)
* catch exceptions from req.cancel() * catch other instances of req.cancel * fix prev commit
This commit is contained in:
@@ -19,6 +19,7 @@ class TaskRestDial extends Task {
|
||||
this.timeout = this.data.timeout || 60;
|
||||
this.sipRequestWithinDialogHook = this.data.sipRequestWithinDialogHook;
|
||||
this.referHook = this.data.referHook;
|
||||
this.recentCallStatus = 0;
|
||||
|
||||
this.on('connect', this._onConnect.bind(this));
|
||||
this.on('callStatus', this._onCallStatus.bind(this));
|
||||
@@ -57,7 +58,11 @@ class TaskRestDial extends Task {
|
||||
this._clearCallTimer();
|
||||
if (this.canCancel) {
|
||||
this.canCancel = false;
|
||||
cs?.req?.cancel();
|
||||
try {
|
||||
cs?.req?.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||
}
|
||||
}
|
||||
this.notifyTaskDone();
|
||||
}
|
||||
@@ -118,7 +123,8 @@ class TaskRestDial extends Task {
|
||||
}
|
||||
|
||||
_onCallStatus(status) {
|
||||
this.logger.debug(`CallStatus: ${status}`);
|
||||
this.logger.debug(`RestDial CallStatus: ${status}`);
|
||||
this.recentCallStatus = status;
|
||||
if (status >= 200) {
|
||||
this.canCancel = false;
|
||||
this._clearCallTimer();
|
||||
@@ -136,11 +142,16 @@ class TaskRestDial extends Task {
|
||||
}
|
||||
|
||||
_onCallTimeout() {
|
||||
this.logger.debug('TaskRestDial: timeout expired without answer, killing task');
|
||||
this.logger.debug(`TaskRestDial: timeout expired without answer, last status ${this.recentCallStatus}`);
|
||||
this.timer = null;
|
||||
if (this.canCancel) {
|
||||
if (this.canCancel && this.recentCallStatus < 200) {
|
||||
this.logger.debug('TaskRestDial: cancelling call attempt');
|
||||
this.canCancel = false;
|
||||
this.cs?.req?.cancel();
|
||||
try {
|
||||
this.cs?.req?.cancel();
|
||||
} catch (err) {
|
||||
this.logger.error({err}, 'TaskRestDial: error cancelling call');
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user