That should just work, provided the Exception is a \Stripe\Error\Card. Are you sure about that? Can you post a stacktrace?
Jan 12, 2016
2
Level 2
Try Catch not being handled in Artisan Command
Hi,
I have a try catch block in one of the command. Problem is when error occurs Laravel takes over and my catch block never happens. I read the error docs on L5.1 but not sure how it works with the ErrorHandler. Here is my block:
try {
$re = \Stripe\Refund::create([
'charge' => $booking->stripe_charge_id,
]);
} catch(\Stripe\Error\InvalidRequest $e) {
// Since it's a decline, \Stripe\Error\Card will be caught
$body = $e->getJsonBody();
$err = $body['error'];
$err_status = $e->getHttpStatus();
$err_type = array_key_exists('type' , $err) ? $err['type'] : '';
$err_code = array_key_exists('code' , $err) ? $err['code'] : '';
$err_param = array_key_exists('param' , $err) ? $err['param'] : '';
$err_message = array_key_exists('message', $err) ? $err['message'] : '';
}
Is it something like in Exceptions/handler.php:
// Stripe exceptions
if ($e instanceof \Stripe\Error\InvalidRequest) {
// Do something ?
}
If yes how do I get the variables I had in my ongoing command? I need specific error responses depending on the case.
Thanks!
Level 6
1 like
Please or to participate in this conversation.