From 812073b148baeb58ac938b2c74c289b12babcf25 Mon Sep 17 00:00:00 2001 From: songtianlun Date: Wed, 8 Jan 2025 17:46:07 +0800 Subject: [PATCH] fix: handle user activation email errors - Wrap the activation email sending in a begin-rescue block - Log error messages if sending fails - Provide user feedback with an error message and render the new user form again This change improves the user experience by handling potential errors during the user activation email process. If an error occurs, it logs the issue and informs the user to try again, preventing confusion and enhancing the robustness of the registration flow. --- app/controllers/users_controller.rb | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/controllers/users_controller.rb b/app/controllers/users_controller.rb index 4415b7c..318c31e 100644 --- a/app/controllers/users_controller.rb +++ b/app/controllers/users_controller.rb @@ -28,9 +28,15 @@ class UsersController < ApplicationController # flash[:success] = "Welcome to the Sample App!" # redirect_to @user # redirect_to user_url(@user) - @user.send_activation_email - flash[:info] = "Please check your email to activate your account." - redirect_to root_url + begin + @user.send_activation_email + flash[:info] = "Please check your email to activate your account." + redirect_to root_url + rescue => e + logger.error "User creation failed: #{e.message}" + flash[:error] = "Something went wrong. Please try again." + render "new", status: :unprocessable_entity + end else render "new", status: :unprocessable_entity end