From d1e983ed97ff31310d7065ef2c27203ff43e2e68 Mon Sep 17 00:00:00 2001 From: mfo Date: Mon, 17 Jun 2024 13:25:28 +0200 Subject: [PATCH] fix(EmailCheckerController): with partial email, should not raise error --- app/lib/email_checker.rb | 2 ++ spec/controllers/email_checker_controller_spec.rb | 8 ++++++++ 2 files changed, 10 insertions(+) diff --git a/app/lib/email_checker.rb b/app/lib/email_checker.rb index c2cbe3536..e2d2d5222 100644 --- a/app/lib/email_checker.rb +++ b/app/lib/email_checker.rb @@ -627,6 +627,8 @@ class EmailChecker return { success: true } if similar_domains.empty? { success: true, email_suggestions: email_suggestions(parsed_email:, similar_domains:) } + rescue Mail::Field::IncompleteParseError + return { success: false } end private diff --git a/spec/controllers/email_checker_controller_spec.rb b/spec/controllers/email_checker_controller_spec.rb index 4572c2cd4..685bd5de9 100644 --- a/spec/controllers/email_checker_controller_spec.rb +++ b/spec/controllers/email_checker_controller_spec.rb @@ -35,5 +35,13 @@ describe EmailCheckerController, type: :controller do expect(body).to eq({ success: false }) end end + + context 'incomplete' do + let(:params) { { email: 'bikram.subedi81@' } } + it do + expect(response).to have_http_status(:success) + expect(body).to eq({ success: false }) + end + end end end