From ac263de72980bbc7b22a5d715720f28ab1418124 Mon Sep 17 00:00:00 2001 From: Dave Horton Date: Wed, 22 Sep 2021 10:54:36 -0400 Subject: [PATCH] fix error responses for sms --- lib/tasks/message.js | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/lib/tasks/message.js b/lib/tasks/message.js index f1fa65d2..72311060 100644 --- a/lib/tasks/message.js +++ b/lib/tasks/message.js @@ -60,16 +60,27 @@ class TaskMessage extends Task { return res.sendStatus(404); } if (url) { - const post = bent(url, 'POST', 'json', 201); + const post = bent(url, 'POST', 'json', 201, 480); this.logger.info({payload, url}, 'Message:exec sending outbound SMS'); const response = await post(relativeUrl, payload); - this.logger.info({response}, 'Successfully sent SMS'); - if (cs.callInfo.res) { - this.logger.info('Message:exec sending 200 OK response to HTTP POST from api server'); - res.status(200).json({ - sid: cs.callInfo.messageSid, - providerResponse: response - }); + if (response.smpp_err_code) { + this.logger.info({response}, 'Error sending SMS'); + if (cs.callInfo.res) { + res.status(480).json({ + ...response, + sid: cs.callInfo.messageSid + }); + } + } + else { + this.logger.info({response}, 'Successfully sent SMS'); + if (cs.callInfo.res) { + this.logger.info('Message:exec sending 200 OK response to HTTP POST from api server'); + res.status(200).json({ + sid: cs.callInfo.messageSid, + providerResponse: response + }); + } } // TODO: action Hook