我发送otp使用twilio,laravel,消息现在正在工作,但我想设置例外,如果消息未送达等我试过像
public function send_otp()
{
try {
$account_sid = env('TWILIO_ACCOUNT_SID');
$auth_token = env('TWILIO_AUTH_TOKEN');
$number=Auth::user()->user_phone;
$client = new Client($account_sid, $auth_token);
$messages = $client->messages->create($number, array(
'From' => '+12533368077',
'Body' => Auth::user()->user_otp,
));
dd($messages);
//return $messages;
//throw new Exception();
} catch (Exception $e) {
return response()->json(['error' => true,'message'=>'Something went wrong'],200);
}
}
你可以帮我解决这个问题吗
答案 0 :(得分:1)
设置env
数据后,您是否清除了缓存?
php artisan config:cache
如果你想处理错误 - laravel有特殊的逻辑。你需要抓住那个错误,然后采取行动,这很简单: https://laravel.com/docs/5.6/errors
public function render($request, Exception $exception)
{
if ($exception instanceof CustomException) {
return response()->view('errors.custom', [], 500);
}
return parent::render($request, $exception);
}