Skip to content

Commit

Permalink
enhancement: log errors rescued perform_action_and_record_errors (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul-Bob authored Feb 12, 2025
1 parent 42d738b commit dfa3f6a
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions app/controllers/avo/base_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -241,12 +241,16 @@ def perform_action_and_record_errors(&block)
begin
succeeded = block.call
rescue ActiveRecord::RecordInvalid => error
log_error error

# Do nothing as the record errors are already being displayed
# On associations controller add errors from join record to record
if controller_name == "associations"
@record.errors.add(:base, error.message)
end
rescue => exception
log_error exception

# In case there's an error somewhere else than the record
# Example: When you save a license that should create a user for it and creating that user throws and error.
# Example: When you Try to delete a record and has a foreign key constraint.
Expand All @@ -258,6 +262,13 @@ def perform_action_and_record_errors(&block)
@record.errors.any? ? false : succeeded
end

def log_error(error)
return if Rails.env.production?

Rails.logger.error error
Rails.logger.error error.backtrace.join("\n")
end

def model_params
request_params = params.require(model_param_key).permit(permitted_params)

Expand Down

0 comments on commit dfa3f6a

Please sign in to comment.