Catch a NEXMO error in Laravel

I am trying to send SMS to phone numbers entered by users into my applications, I'm making an AJAX post request using AXIOS to the PHP functions that send the SMS using NEXMO's API. When message delivers I have no issue, but whenever it does deliver, i get an Internal Server Error

在这里输入图像描述

This is the NEXMO Code I am using.

$message = Nexmo::message()->send([
    'to' => '234' . $phone->number,
    'from' => 'NEXMO',
    'text' => $text
]);

Which is working fine when phone number is rightly formatted and also if there is good network to deliver the SMS, but once there is any issue in sending the SMS, it generates an internal server error.

I have tried using a TRY and CATCH like below

try
{
  $message = Nexmo::message()->send([
    'to' => '234' . $phone->number,
    'from' => 'NEXMO',
    'text' => $text
  ]);
}catch(Exception $e){
  return $e;
}

It won't work.

I also try returning the value of $message['status'] and $message['err-code']. It only works when message successfully sends other times it returns an Internal Server error still.

Please how do I catch a situation where my message didn't get sent and report back to user through AJAX

链接地址: http://www.djcxy.com/p/5662.html

上一篇: 所有Nexmo API调用中都有404错误

下一篇: 在Laravel中捕获NEXMO错误