Skip to content

Commit

Permalink
Use Rails 7 default error reporting (#335)
Browse files Browse the repository at this point in the history
  • Loading branch information
timpeat authored Jul 5, 2023
1 parent fde82f1 commit ac51b65
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 25 deletions.
6 changes: 3 additions & 3 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,10 @@ GEM
rexml (~> 3.2, >= 3.2.5)
rubyzip (>= 1.2.2, < 3.0)
websocket (~> 1.0)
sentry-rails (5.8.0)
sentry-rails (5.9.0)
railties (>= 5.0)
sentry-ruby (~> 5.8.0)
sentry-ruby (5.8.0)
sentry-ruby (~> 5.9.0)
sentry-ruby (5.9.0)
concurrent-ruby (~> 1.0, >= 1.0.2)
simplecov (0.22.0)
docile (~> 1.1)
Expand Down
6 changes: 3 additions & 3 deletions app/models/application_search.rb
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ def datastore_params
end

def datastore_response
http_client.post('/searches', datastore_params)
rescue DatastoreApi::Errors::BadRequest
{ records: [], pagination: {} }
Rails.error.handle(DatastoreApi::Errors::BadRequest, fallback: -> { { records: [], pagination: {} } }) do
http_client.post('/searches', datastore_params)
end
end
end
7 changes: 3 additions & 4 deletions app/models/sns_event/receive_application_event.rb
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,9 @@ def invalid?
end

def json(from:)
JSON.parse(from)
rescue StandardError => e
Rails.logger.error("Error parsing JSON [#{e.class}] `#{e.message}`")
{}
Rails.error.handle(fallback: -> { {} }) do
JSON.parse(from)
end
end

def to_json(*args)
Expand Down
11 changes: 4 additions & 7 deletions app/notifiers/access_granted_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
class AccessGrantedNotifier
def call(event)
email = User.find(event.data.fetch(:user_id)).email
NotifyMailer.access_granted_email(email).deliver_now
#
# Rescue and report exceptions
# Notifying should not block
rescue StandardError => e
Sentry.capture_exception(e)
Rails.error.handle do
email = User.find(event.data.fetch(:user_id)).email
NotifyMailer.access_granted_email(email).deliver_now
end
end
end
15 changes: 7 additions & 8 deletions app/notifiers/sent_back_notifier.rb
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
class SentBackNotifier
def call(event)
application_id = event.data.fetch(:application_id)
return_reason = event.data.fetch(:reason)
Rails.error.handle do
application_id = event.data.fetch(:application_id)
return_reason = event.data.fetch(:reason)

NotifyMailer.application_returned_email(application_id, return_reason).deliver_now

# Rescue and report exceptions
# Notifying should not block
rescue StandardError => e
Sentry.capture_exception(e)
NotifyMailer.application_returned_email(
application_id, return_reason
).deliver_now
end
end
end
1 change: 1 addition & 0 deletions config/initializers/sentry.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
Rails.application.config.to_prepare do
# Sentry is enabled if SENTRY_DSN environment variable is set
Sentry.init do |config|
config.rails.report_rescued_exceptions = true
config.breadcrumbs_logger = [:active_support_logger, :http_logger]
config.environment = HostEnv.env_name

Expand Down

0 comments on commit ac51b65

Please sign in to comment.