stripe-perl
stripe-perl copied to clipboard
Error from Stripe just dies
Whenever there is an error from stripe, Net::Stripe just uses "die" to kill the script. It would be much more useful if an error object was returned with the error message and the field that had the error
Can you provide an example? Normally Net::Stripe dies with a Net::Stripe::Error. Combined with Try::Tiny it is very easy to catch.
Sure! Here's an example:
my $stripe = Net::Stripe->new(api_key => $API_KEY);
my $card = Net::Stripe::Card->new( number => '4242424242424242', cvc => '333', name => 'Test name', address_line1 => '2145 Barkers Lane', address_line2 => 'Apt. 907', address_zip => '78254', address_state => 'TX', exp_month => '06', exp_year=> '15', );
my $customer = $stripe->post_customer( card => $card, email => '[email protected]', description => 'Test for Net::Stripe', );
I guess I could just use Try::Tiny to catch it and then use regex on the error message to see what fields are incorrect. I just thought there might be something more elegant than the script dying, like maybe the customer object having an error field set to 1 or set to a Net::Stripe::Error object (since that has the error message already), and then the user could check $customer->error, and maybe if they try to use some other method on the customer object and the error field is set then script dies giving the error message. That way the user wouldn't have to worry about using Try::Tiny for every call and could just check the error field. Of course, maybe you have a reason that using Try::Tiny outside of Net::Stripe is better? I didn't write the module so maybe that wouldn't work well with how it's written.