【问题标题】:Twilio - get error code on sms send failureTwilio - 在短信发送失败时获取错误代码
【发布时间】:2017-07-24 17:06:23
【问题描述】:

我们的代码通过执行以下操作发送 twilio 短信:

// send the text message to the member's mobile phone 
try {

// attempt to send the message through Twilio
$tw_msg = $twilio_client->messages->create(
    "+1".$recipient['address'],
    array (
        'From' => "+1".$org['twilio_number'],
        'Body' => $txtmsg,
        'StatusCallback' => CALLBACK_LINK.'/text_message_handler.php'
    )
);

// else trap the error since the message could not be sent and the callback routine is not called
} catch (Exception $e) {

    // process the text message error 
    process_text_msg_error($db, $e, $org, $msg, $recipient);
}

在 v4 库中,我们将通过执行以下操作获得错误代码:

// get the twilio error components 
$twilio_error_status = $e->getStatus();
$twilio_error_code = $e->getCode();
$twilio_error_msg = $e->getMessage();

这并没有为我们提供使用 V5 库的预期效果。我们如何使用 V5 lib 获取错误状态和代码?

【问题讨论】:

  • 当您处理错误时,您从 v5 库中得到了什么?
  • 这是一个数组,我必须通过电子邮件将其发送给您。

标签: php rest twilio


【解决方案1】:

这里是 Twilio 开发者宣传员。

在我看来,您需要更新对异常调用的方法之一以获取状态代码。异常现在是RestException 并具有getStatusCode() 方法。你应该更新到:

// get the twilio error components 
$twilio_error_status = $e->getStatusCode();
$twilio_error_code = $e->getCode();
$twilio_error_msg = $e->getMessage();

让我知道这是否有帮助。

【讨论】:

  • 是的,这给了我们 400 代码。其他两个字段怎么样,我们如何获得它们?我们想要特定的 5 位错误代码。 400 只是表示 https 请求创建消息失败。
  • getCodegetMessage 方法是否没有给出 5 位错误代码?
  • 我的错!他们正在工作,我未能将它们添加到日志文件中。谢谢我的朋友。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2017-12-15
  • 1970-01-01
相关资源
最近更新 更多