You can return whatever kind of response you need to from the catch part, or even throw another exception if needed.
Nov 13, 2018
3
Level 6
Try/catch with Stripe API
Something that didn't occur to me before now on building this app is how to handle errors that don't come from my own code.
I have an AccountController that shows the users subscription status and a list of previous charges on Stripe.
However, when I logged in tonight, and it tried to pull from Stripe, their API had issues. Now I do have a try/catch statement
try {
Stripe::setApiKey(env('STRIPE_SECRET'));
$invoices = $user->invoices();
} catch (\Exception $ex) {
return $ex->getMessage();
}
However, the returned message is just text. I wish to return that error to my view as well as give all the other data pertaining to account.
Please or to participate in this conversation.