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.

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

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度