user9555022
user9555022

Reputation:

Twilio sms not handling exception

My application sends an sms message when a user signs up. I'm trying to handle the exception if the number is invalid, and Twilio fails to send it. But when the message fails, it never seems to reach the catch in my try/catch clause.

try {
    $message = $twilio->messages
        ->create(
            "$user->phone", // to
            array("from" => "$siteNumber", "body" => "$message_text")
        );
} catch (TwilioException $e) {
    return $e->getMessage();
}

I've also tried the following catch conditions.

} catch (\Services_Twilio_RestException $e) {
    return $e->getMessage();
}

catch (RestException $e) {
    return redirect()->back()->withFlashSuccess("Failed To Send Text");
}

Upvotes: 2

Views: 1531

Answers (1)

Sachin Saini
Sachin Saini

Reputation: 401

Please try to change the catch exception

catch (\Exception $e) {
return $e->getMessage();
}

It's working for me

Upvotes: 1

Related Questions