From b66c6627ed9de7caf07c8dd9d0bb1fc60067b687 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Mon, 30 Mar 2020 10:19:34 -0400 Subject: [PATCH] return 480 when failing due to no media server --- lib/session/call-session.js | 5 ++++- lib/session/inbound-call-session.js | 14 ++++++++++++-- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index 6d45f4d3..f50ccb44 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -533,7 +533,10 @@ class CallSession extends Emitter { getMS() { if (!this.ms) { this.ms = this.srf.locals.getFreeswitch(); - if (!this.ms) throw new Error('no available freeswitch'); + if (!this.ms) { + this._mediaServerFailure = true; + throw new Error('no available freeswitch'); + } } return this.ms; } diff --git a/lib/session/inbound-call-session.js b/lib/session/inbound-call-session.js index 70e74972..f591a53e 100644 --- a/lib/session/inbound-call-session.js +++ b/lib/session/inbound-call-session.js @@ -28,8 +28,18 @@ class InboundCallSession extends CallSession { _onTasksDone() { if (!this.res.finalResponseSent) { - this.logger.info('InboundCallSession:_onTasksDone auto-generating non-success response to invite'); - this.res.send(603); + if (this._mediaServerFailure) { + this.logger.info('InboundCallSession:_onTasksDone generating 480 due to media server failure'); + this.res.send(480, { + headers: { + 'X-Reason': 'crankback: media server failure' + } + }); + } + else { + this.logger.info('InboundCallSession:_onTasksDone auto-generating non-success response to invite'); + this.res.send(603); + } } }