簡體   English   中英

Twilio-在短信發送失敗時獲取錯誤代碼

[英]Twilio - get error code on sms send failure

我們的代碼通過執行以下操作發送twilio sms消息:

// 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庫獲取錯誤狀態和代碼?

Twilio開發人員布道者在這里。

在我看來,您需要更新對異常調用的方法之一才能獲取狀態代碼。 現在,異常是RestException並且具有方法getStatusCode() 您應該更新為:

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

讓我知道是否有幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM