我正在将twilio集成到我的laravel 5应用程序中。为了在框架中使用它,我使用aloha/laravel-twilio集成。
使用test-credentials发送有效请求工作正常。当我想要实现error-handling时遇到问题。
由于某种原因,catch没有捕获错误,这导致应用程序崩溃。如果我正确地读取错误消息,则错误似乎在twilio-sdk中。
以下是我迄今为止所做的:
这会导致以下错误:
从文档来看,应该会抛出这个错误(不是有效的电话号码),但我应该有可能捕获和处理它。目前,这并没有起作用。我无法捕获到这个错误...
如何捕获和处理 twilio-errors?
使用test-credentials发送有效请求工作正常。当我想要实现error-handling时遇到问题。
由于某种原因,catch没有捕获错误,这导致应用程序崩溃。如果我正确地读取错误消息,则错误似乎在twilio-sdk中。
以下是我迄今为止所做的:
<?php namespace App;
use Illuminate\Database\Eloquent\Model;
use Aloha\Twilio\TwilioInterface;
class Activation extends Model {
protected $fillable = array( 'a', 'b', 'c');
public static function send() {
// Testaccount
// $toNumber = '+15005550006'; // valid number; works fine
$toNumber = '+15005550001'; // @todo will throw an exeption, and breaks the app
try {
\Twilio::message( $toNumber, 'Pink Elephants and Happy Rainbows');
} catch ( Services_Twilio_RestException $e ) {
elog( 'EACT', $e->getMessage( ) , __FUNCTION__ ); // this is not called when an twilio error occurs
}
}
}
这会导致以下错误:
Whoops, looks like something went wrong.
Services_Twilio_RestException in /path/to/my/laravel/vendor/twilio/sdk/Services/Twilio.php line 297
Exception_message: The 'To' number +15005550001 is not a valid phone number.
从文档来看,应该会抛出这个错误(不是有效的电话号码),但我应该有可能捕获和处理它。目前,这并没有起作用。我无法捕获到这个错误...
如何捕获和处理 twilio-errors?