Skip to content

Commit 545bb52

Browse files
committed
fix: add handler for ActiveRecord::RecordInvalid exceptions
1 parent 299c366 commit 545bb52

1 file changed

Lines changed: 6 additions & 0 deletions

File tree

app/controllers/application_controller.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,12 @@ class ApplicationController < ActionController::Base
1919
rescue_from ActionController::RoutingError, with: :render_not_found
2020
rescue_from ActiveRecord::RecordNotFound, with: :render_not_found
2121

22+
rescue_from ActiveRecord::RecordInvalid do |exception|
23+
Rails.logger.error("Validation failed: #{exception.message}")
24+
redirect_back(fallback_location: root_path,
25+
alert: 'Unable to complete action. Please check your input and try again.')
26+
end
27+
2228
rescue_from Pundit::NotAuthorizedError, with: :user_not_authorized
2329
rescue_from Pundit::AuthorizationNotPerformedError, with: :user_not_authorized
2430

0 commit comments

Comments
 (0)