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