From 8bed44cce3446dd2f632e9d6fe49c1c95fa70a37 Mon Sep 17 00:00:00 2001 From: rammohan-y <37395033+rammohan-y@users.noreply.github.com> Date: Mon, 24 Feb 2025 23:14:25 +0530 Subject: [PATCH] sending jambonz:error when the incoming message is not parsable (#1095) * sending jambonz:error when the incoming message is not parsable https://github.com/jambonz/jambonz-feature-server/issues/1094 * writing an alert when incoming paylod is invalid * added content to the jambonz:error payload --- lib/utils/ws-requestor.js | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/lib/utils/ws-requestor.js b/lib/utils/ws-requestor.js index 4fbecaae..f79a2482 100644 --- a/lib/utils/ws-requestor.js +++ b/lib/utils/ws-requestor.js @@ -431,6 +431,21 @@ class WsRequestor extends BaseRequestor { } } catch (err) { this.logger.info({err, content}, 'WsRequestor:_onMessage - invalid incoming message'); + const params = { + msg: 'InvalidMessage', + details: err.message, + content: Buffer.from(content).toString('utf-8') + }; + const {writeAlerts, AlertType} = this.Alerter; + writeAlerts({ + account_sid: this.account_sid, + alert_type: AlertType.INVALID_APP_PAYLOAD, + target_sid: this.call_sid, + message: err.message, + + }).catch((err) => this.logger.info({err}, 'Error generating alert for invalid message')); + this.request('jambonz:error', '/error', params) + .catch((err) => this.logger.debug({err}, 'WsRequestor:_onMessage - Error sending')); } }