Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

enhancement: log errors rescued in perform_action_and_record_errors #3658

Merged
merged 1 commit into from
Feb 12, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading