Module: Dbviewer::ErrorHandling
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/dbviewer/error_handling.rb
Instance Method Summary collapse
-
#handle_database_error(exception) ⇒ Object
Handle database connection errors.
- #log_error(error, prefix = "Error") ⇒ Object
Instance Method Details
#handle_database_error(exception) ⇒ Object
Handle database connection errors
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'app/controllers/concerns/dbviewer/error_handling.rb', line 11 def handle_database_error(exception) = case exception when ActiveRecord::ConnectionNotEstablished "Database connection could not be established." when ActiveRecord::StatementInvalid "Invalid SQL statement: #{exception.}" else "Database error: #{exception.}" end flash.now[:error] = Rails.logger.error("Database error: #{exception.}\n#{exception.backtrace.join("\n")}") # Determine where to redirect based on the current action if action_name == "show" || action_name == "query" @error = @records = nil render action_name else @tables = [] render :index end end |
#log_error(error, prefix = "Error") ⇒ Object
35 36 37 38 39 40 |
# File 'app/controllers/concerns/dbviewer/error_handling.rb', line 35 def log_error(error, prefix = "Error") error_msg = "#{prefix}: #{error.}" flash.now[:error] = error_msg Rails.logger.error("#{prefix}: #{error.}\n#{error.backtrace.join("\n")}") error_msg end |