From dc582e5980a089c0826e0764d1c8b5b23e5d766f Mon Sep 17 00:00:00 2001 From: Matt Dunn-Rankin Date: Sat, 7 Jan 2017 19:19:44 -0800 Subject: [PATCH] donation error handling --- app/controllers/donations_controller.rb | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/app/controllers/donations_controller.rb b/app/controllers/donations_controller.rb index e818065b..438646ac 100644 --- a/app/controllers/donations_controller.rb +++ b/app/controllers/donations_controller.rb @@ -1,9 +1,20 @@ class DonationsController < ApplicationController def create @campaign = Campaign.current - @donation = Donation.create_from_charge( - @campaign, current_user, params[:donation]) - redirect_to @donation + begin + @donation = Donation.create_from_charge( + @campaign, current_user, params[:donation]) + rescue Stripe::CardError => e + flash[:alert] = "We couldn't process your donation: #{e.message}" + redirect_to :donate + rescue => e + flash[:alert] = + "We couldn't process your donation: #{e.message} " + + "Please try again later!" + redirect_to :donate + else + redirect_to @donation + end end def show