我正在我的 laravel 5 应用程序中实现 twilio。为了在我使用aloha/laravel-twilio
集成的框架中使用它。
发送带有测试凭据的有效请求可以正常工作。当我想实现错误处理时遇到问题。
由于某种原因,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 错误?