dounangshen6553 2017-07-24 17:06
浏览 179
已采纳

Twilio - 获取短信发送失败的错误代码

Our code sends twilio sms messages by doing the following:

// 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);
}

In the v4 library we would get the error code by doing the following:

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

This is not giving us what we expected using the V5 library. How do we get the error status and code using the V5 lib?

  • 写回答

1条回答 默认 最新

  • dongliang1893 2017-07-24 17:16
    关注

    Twilio developer evangelist here.

    It looks to me like you need to update one of the methods you call on the exception to get the status code. The exception is now a RestException and has the method getStatusCode(). You should update to:

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

    Let me know if that helps at all.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 LiBeAs的带隙等于0.997eV,计算阴离子的N和P
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 matlab有关常微分方程的问题求解决
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算
  • ¥15 java如何提取出pdf里的文字?
  • ¥100 求三轴之间相互配合画圆以及直线的算法