Skip to content

Commit 865247b

Browse files
author
David Zuckerman
committed
renamed mail-connectivity check, generalized public errors
1 parent 68a3fcd commit 865247b

File tree

2 files changed

+15
-13
lines changed

2 files changed

+15
-13
lines changed

config/initializers/okcomputer.rb

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
require 'net/smtp'
2+
13
# frozen_string_literal: true
24

35
# Health check configuration
@@ -6,7 +8,7 @@
68
OkComputer.check_in_parallel = true
79

810
class AlmaPatronCheck < OkComputer::Check
9-
TEST_PATRON_ID = '[email protected]'
11+
TEST_PATRON_ID = '[email protected]'.freeze
1012

1113
def check
1214
Alma::User.find(TEST_PATRON_ID)
@@ -19,8 +21,9 @@ def check
1921
end
2022

2123
# rubocop:disable Metrics/MethodLength, Metrics/AbcSize
22-
class CustomMailerCheck < OkComputer::Check
23-
require 'net/smtp'
24+
class MailConnectivityCheck < OkComputer::Check
25+
OkComputer::Registry.register 'mail-connectivity', MailConnectivityCheck.new if ActionMailer::Base.delivery_method == :smtp
26+
2427
# Check that the mail password is set
2528
def check
2629
settings = ActionMailer::Base.smtp_settings
@@ -36,17 +39,21 @@ def check
3639
) { mark_message 'Connection for smtp successful' }
3740
rescue Net::SMTPAuthenticationError => e
3841
mark_failure
39-
mark_message "Authentication error: #{e.message}"
42+
Rails.logger.warn "SMTP authentication error: #{e}"
43+
mark_message 'SMTP Error: Authentication failed. Check logs for more details'
4044
rescue Net::SMTPServerBusy, Net::SMTPSyntaxError, Net::SMTPFatalError, Net::SMTPUnknownError => e
4145
mark_failure
42-
mark_message "SMTP error: #{e.message}"
46+
Rails.logger.warn "SMTP Error: #{e}"
47+
mark_message 'SMTP error. Check logs for more details'
4348
rescue IOError, Net::ReadTimeout => e
4449
mark_failure
45-
mark_message "Connection error: #{e.message}"
50+
Rails.logger.warn "SMTP Timeout: #{e}"
51+
mark_message 'SMTP Connection error: Timeout. Check logs for more details'
4652
rescue StandardError => e
4753
# Catch any other unexpected errors
4854
mark_failure
49-
mark_message "An unexpected error occurred: #{e.message}"
55+
Rails.logger.warn "SMTP standard error: #{e}"
56+
mark_message 'SMTP ERROR: Could not connect. Check logs for more details'
5057
end
5158
end
5259
end
@@ -57,7 +64,3 @@ def check
5764

5865
# Ensure database migrations have been run.
5966
OkComputer::Registry.register 'database-migrations', OkComputer::ActiveRecordMigrationsCheck.new
60-
61-
# Ensure connectivity to the mail system.
62-
OkComputer::Registry.register 'custom-mailer', CustomMailerCheck.new
63-
OkComputer::Registry.register 'action-mailer', OkComputer::ActionMailerCheck.new

spec/request/okcomputer_spec.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,7 @@
1111
it 'returns all checks to /health' do
1212
get '/health'
1313
expect(response.parsed_body.keys).to match_array %w[
14-
action-mailer
15-
custom-mailer
14+
mailer-connectivity
1615
alma-patron-lookup
1716
default
1817
database

0 commit comments

Comments
 (0)