stripe-perl icon indicating copy to clipboard operation
stripe-perl copied to clipboard

Error from Stripe just dies

Open srchulo opened this issue 11 years ago • 2 comments
trafficstars

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

srchulo avatar May 11 '14 18:05 srchulo

Can you provide an example? Normally Net::Stripe dies with a Net::Stripe::Error. Combined with Try::Tiny it is very easy to catch.

rustyconover avatar May 12 '14 00:05 rustyconover

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.

srchulo avatar May 12 '14 00:05 srchulo