【发布时间】:2015-08-16 10:53:43
【问题描述】:
我正在我的 laravel 5 应用程序中实现 twilio。为了在框架中使用它,我使用aloha/laravel-twilio 集成。
使用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 错误?
【问题讨论】:
-
你解决了吗?我面临同样的问题。如果完成,请在此处粘贴解决方案。
-
我得到了以下解决方案。
标签: php laravel-5 try-catch twilio twilio-php