Skip to content

Commit 479e59e

Browse files
committed
WIP claude fix user login bugsnag
1 parent c134b74 commit 479e59e

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

app/controllers/users/passwords_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,12 @@ def send_password
4747

4848
def send_password_reset_mail
4949
@reset_token = @resource.send_reset_password_instructions # generate a reset token and call devise mailer
50+
rescue Net::ReadTimeout, Net::OpenTimeout, Timeout::Error => e
51+
# Log the error but don't expose it to the user for security reasons
52+
Rails.logger.error("Password reset email failed to send: #{e.class} - #{e.message}")
53+
Bugsnag.notify(e) if defined?(Bugsnag)
54+
# Still generate a token so SMS can potentially work
55+
@reset_token = @resource.generate_password_reset_token
5056
end
5157

5258
def send_password_reset_sms

config/environments/production.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@
1515
user_name: ENV["SENDINBLUE_EMAIL"],
1616
password: ENV["SENDINBLUE_PASSWORD"],
1717
authentication: "login",
18-
enable_starttls_auto: true
18+
enable_starttls_auto: true,
19+
open_timeout: 5, # Timeout for opening connection (seconds)
20+
read_timeout: 5 # Timeout for reading response (seconds)
1921
}
2022
# Code is not reloaded between requests.
2123
config.enable_reloading = false

spec/requests/users/passwords_spec.rb

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,27 @@
122122
)
123123
end
124124
end
125+
126+
context "when email sending times out" do
127+
let(:params) { {user: {email: user.email, phone_number: ""}} }
128+
129+
before do
130+
allow_any_instance_of(User).to receive(:send_reset_password_instructions).and_raise(Net::ReadTimeout)
131+
end
132+
133+
it "handles the timeout gracefully and still shows success message" do
134+
expect(Rails.logger).to receive(:error).with(/Password reset email failed to send/)
135+
request
136+
expect(flash[:notice]).to(
137+
eq("If the account exists you will receive an email or SMS with instructions on how to reset your password in a few minutes.")
138+
)
139+
end
140+
141+
it "does not crash the request" do
142+
expect { request }.not_to raise_error
143+
expect(response).to redirect_to(user_session_url)
144+
end
145+
end
125146
end
126147

127148
describe "PUT /update" do

0 commit comments

Comments
 (0)