File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -32,13 +32,22 @@ def create
3232 authorize @volunteer
3333
3434 if @volunteer . save
35- @volunteer . invite! ( current_user )
35+ # invitation error handling
36+ begin
37+ @volunteer . invite! ( current_user )
38+ rescue => e
39+ flash [ :alert ] = "Volunteer invitation failed. Reason: #{ e . message } "
40+ end
41+
3642 # call short io api here
37- raw_token = @volunteer . raw_invitation_token
38- invitation_url = Rails . application . routes . url_helpers . accept_user_invitation_url ( invitation_token : raw_token , host : request . base_url )
39- hash_of_short_urls = @volunteer . phone_number . blank? ? { 0 => nil , 1 => nil } : handle_short_url ( [ invitation_url , request . base_url + "/users/edit" ] )
40- body_msg = account_activation_msg ( "volunteer" , hash_of_short_urls )
41- sms_status = deliver_sms_to @volunteer , body_msg
43+ invitation_url = Rails . application . routes . url_helpers . accept_user_invitation_url ( invitation_token : @volunteer . raw_invitation_token , host : request . base_url )
44+
45+ hash_of_short_urls = { 0 => nil , 1 => nil }
46+ if @volunteer . phone_number . present?
47+ hash_of_short_urls = handle_short_url ( [ invitation_url , request . base_url + "/users/edit" ] )
48+ end
49+
50+ sms_status = deliver_sms_to @volunteer , account_activation_msg ( "volunteer" , hash_of_short_urls )
4251 redirect_to edit_volunteer_path ( @volunteer ) , notice : sms_acct_creation_notice ( "volunteer" , sms_status )
4352 else
4453 render :new , status : :unprocessable_entity
You can’t perform that action at this time.
0 commit comments