From b478e0ecd270762e2a4c2aab93e234e1cb3fca4e Mon Sep 17 00:00:00 2001 From: Sam Machin Date: Wed, 30 Jul 2025 13:32:15 +0100 Subject: [PATCH] fix assert, and force methods to upper case (#1304) * fix assert, and force methods to upper case * add alert for updateCall errors * lint * handle missing method --- lib/session/call-session.js | 11 +++++++++++ lib/utils/http-requestor.js | 6 +++--- 2 files changed, 14 insertions(+), 3 deletions(-) diff --git a/lib/session/call-session.js b/lib/session/call-session.js index e768c769..22176319 100644 --- a/lib/session/call-session.js +++ b/lib/session/call-session.js @@ -1963,6 +1963,17 @@ Duration=${duration} ` } } catch (err) { this.logger.info({err, opts, callSid}, 'CallSession:updateCall - error updating call'); + const {writeAlerts} = this.srf.locals; + try { + writeAlerts({ + alert_type: 'error-updating-call', + account_sid: this.accountSid, + message: err.message, + target_sid: callSid + }); + } catch (err) { + this.logger.error({err}, 'Error writing error-updating-call alert'); + } } } diff --git a/lib/utils/http-requestor.js b/lib/utils/http-requestor.js index 773b5801..3e09f20e 100644 --- a/lib/utils/http-requestor.js +++ b/lib/utils/http-requestor.js @@ -41,7 +41,7 @@ class HttpRequestor extends BaseRequestor { constructor(logger, account_sid, hook, secret) { super(logger, account_sid, hook, secret); - this.method = hook.method || 'POST'; + this.method = hook.method?.toUpperCase() || 'POST'; this.authHeader = basicAuth(hook.username, hook.password); this.backoffMs = 500; @@ -111,7 +111,7 @@ class HttpRequestor extends BaseRequestor { const payload = params ? snakeCaseKeys(params, ['customerData', 'sip', 'env_vars', 'args']) : null; const url = hook.url || hook; - const method = hook.method || 'POST'; + const method = hook.method?.toUpperCase() || 'POST'; let buf = ''; httpHeaders = { ...httpHeaders, @@ -119,7 +119,7 @@ class HttpRequestor extends BaseRequestor { }; assert.ok(url, 'HttpRequestor:request url was not provided'); - assert.ok, (['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`); + assert.ok(['GET', 'POST'].includes(method), `HttpRequestor:request method must be 'GET' or 'POST' not ${method}`); const startAt = process.hrtime(); /* if we have an absolute url, and it is ws then do a websocket connection */