Skip to content

Commit 5543b05

Browse files
committed
Added volunteer invitation error handling
1 parent 6ca5e7f commit 5543b05

File tree

1 file changed

+10
-1
lines changed

1 file changed

+10
-1
lines changed

app/controllers/volunteers_controller.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,16 @@ def create
3232
authorize @volunteer
3333

3434
if @volunteer.save && @volunteer.email.match?(URI::MailTo::EMAIL_REGEXP)
35-
@volunteer.invite!(current_user)
35+
36+
# invitation error handling
37+
begin
38+
@volunteer.invite!(current_user)
39+
rescue ActiveRecord::RecordInvalid, StandardError => e
40+
logger.error "Volunteer invitation failed: #{e.message}"
41+
else
42+
logger.info "Volunteer invitation sent successfully"
43+
end
44+
3645
# call short io api here
3746
invitation_url = Rails.application.routes.url_helpers.accept_user_invitation_url(invitation_token: @volunteer.raw_invitation_token, host: request.base_url)
3847

0 commit comments

Comments
 (0)