我正在我的 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 错误?
最佳答案
该类位于命名空间中,因此我必须引用绝对类异常 - \Services_Twilio_RestException
- 在捕获。
它适用于以下代码:
try {
\Twilio::message( $toNumber, 'Pink Elephants and Happy Rainbows');
} catch ( \Services_Twilio_RestException $e ) {
elog( 'EACT', $e->getMessage( ) , __FUNCTION__ );
}
关于php - twilio 捕获错误不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32034259/