#xfechx-error-catching

1 messages · Page 1 of 1 (latest)

merry barn
formal stream
#

I need to catch a There was a problem with your transaction<br>No such subscription

#

but don't really know how to do this

#

it is because in some instances, my code looks for a subscription , and in some cases it is a invoice item

#

so would like to catch the no such subscription error and retrieve a invoice item

merry barn
#

sure but the doc I linked explains all of that

#

it shows all error types, how to handle them in all languages

formal stream
#

yes, but what i would like to know

#

is - already knowing that error:
No such subscription

#

how can I specifically look for that error on my code, so that I can then the code retrieves an invoice item instead of a subscription id

merry barn
#

I don't understand what you mean I;m sorry. You trigger that error by passing a bad subscription id

formal stream
#

I have the page open

#

yes

#

on some instances, the webhook will receive a subscription id

#

on those scenarios the code works

#

when it receives an invoice item, it catches the error and displays the error, but how can I make it so that it retrieves the invoice item

#

I have these catches, I suppose the one being used is invalidrequest

#

catch(\Stripe\Error\InvalidRequest $e){ error_messages($e); } catch (\Stripe\Error\Card $e){ error_messages($e); } catch (Exception $e){ error_messages($e); }

merry barn
#

I am so lost

#

this is just really basic php logging an error

#

can you share a bit more code about the webhook event handler? I don't get what you mean at all this time but maybe more code will help

formal stream
#

ahh sorry

#

ok

#

so, I suppose:
\Stripe\Error\InvalidRequest $e

#

is printing:
``There was a problem with your transaction<br>No such subscription`

#

how can I specifically look for that error? So that my code can do something else

merry barn
#

but what have you tried?

#

I'm sorry but it seems to be the same question as your original message

#

what doesn't work? Did you read the explicit doc I gave you which covers all of this in details?

#

the code you have does error_message($e) that's it. It doesn't handle the exception, look at what;'s inside, etc. But our docs explicitly show you that in the first example on that page I linked you to try { $stripe->paymentIntents->create($args); error_log("No error."); } catch(\Stripe\Exception\CardException $e) { error_log("A payment error occurred: {$e->getError()->message}"); } catch (\Stripe\Exception\InvalidRequestException $e) { error_log("An invalid request occuurred."); } catch (Exception $e) { error_log("Another problem occurred, maybe unrelated to Stripe."); }

#

it clearly shows how to access that error message $e->getError()->message. It also tells you about other features like code and param

formal stream
#

ok, I think I get it

#

sorry

#

will try something

merry barn
#

@formal stream did it work?