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

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.

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

报告相同问题?