diff --git a/app/controllers/volunteers_controller.rb b/app/controllers/volunteers_controller.rb index 519407c3fc..1cb691e115 100644 --- a/app/controllers/volunteers_controller.rb +++ b/app/controllers/volunteers_controller.rb @@ -32,13 +32,22 @@ def create authorize @volunteer if @volunteer.save - @volunteer.invite!(current_user) + # invitation error handling + begin + @volunteer.invite!(current_user) + rescue => e + flash[:alert] = "Volunteer invitation failed. Reason: #{e.message}" + end + # call short io api here - raw_token = @volunteer.raw_invitation_token - invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: raw_token, host: request.base_url) - hash_of_short_urls = @volunteer.phone_number.blank? ? {0 => nil, 1 => nil} : handle_short_url([invitation_url, request.base_url + "/users/edit"]) - body_msg = account_activation_msg("volunteer", hash_of_short_urls) - sms_status = deliver_sms_to @volunteer, body_msg + invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: @volunteer.raw_invitation_token, host: request.base_url) + + hash_of_short_urls = {0 => nil, 1 => nil} + if @volunteer.phone_number.present? + hash_of_short_urls = handle_short_url([invitation_url, request.base_url + "/users/edit"]) + end + + sms_status = deliver_sms_to @volunteer, account_activation_msg("volunteer", hash_of_short_urls) redirect_to edit_volunteer_path(@volunteer), notice: sms_acct_creation_notice("volunteer", sms_status) else render :new, status: :unprocessable_entity