Module: PgSqlTriggers::ErrorHandling
- Extended by:
- ActiveSupport::Concern
- Included in:
- ApplicationController
- Defined in:
- app/controllers/concerns/pg_sql_triggers/error_handling.rb
Instance Method Summary collapse
-
#format_error_for_flash(error) ⇒ String
Handles errors and formats them for display.
-
#handle_kill_switch_error(error, redirect_path: nil) ⇒ void
Handles kill switch errors with appropriate flash message and redirect.
-
#handle_standard_error(error, operation:, redirect_path: nil) ⇒ void
Handles standard errors with logging and flash message.
-
#rescue_pg_sql_triggers_error(error) ⇒ void
Rescues from PgSqlTriggers errors and sets appropriate flash messages.
Instance Method Details
#format_error_for_flash(error) ⇒ String
Handles errors and formats them for display. Returns a formatted error message for flash display.
12 13 14 15 16 17 |
# File 'app/controllers/concerns/pg_sql_triggers/error_handling.rb', line 12 def format_error_for_flash(error) return error.to_s unless error.is_a?(PgSqlTriggers::Error) # Use user_message which includes recovery suggestions error. end |
#handle_kill_switch_error(error, redirect_path: nil) ⇒ void
This method returns an undefined value.
Handles kill switch errors with appropriate flash message and redirect.
39 40 41 42 |
# File 'app/controllers/concerns/pg_sql_triggers/error_handling.rb', line 39 def handle_kill_switch_error(error, redirect_path: nil) flash[:error] = error. redirect_to redirect_path || root_path end |
#handle_standard_error(error, operation:, redirect_path: nil) ⇒ void
This method returns an undefined value.
Handles standard errors with logging and flash message.
50 51 52 53 54 |
# File 'app/controllers/concerns/pg_sql_triggers/error_handling.rb', line 50 def handle_standard_error(error, operation:, redirect_path: nil) Rails.logger.error("#{operation} failed: #{error.}\n#{error.backtrace.join("\n")}") flash[:error] = "#{operation}: #{error.}" redirect_to redirect_path || root_path end |
#rescue_pg_sql_triggers_error(error) ⇒ void
This method returns an undefined value.
Rescues from PgSqlTriggers errors and sets appropriate flash messages.
23 24 25 26 27 28 29 30 31 32 |
# File 'app/controllers/concerns/pg_sql_triggers/error_handling.rb', line 23 def rescue_pg_sql_triggers_error(error) Rails.logger.error("#{error.class.name}: #{error.}") Rails.logger.error(error.backtrace.join("\n")) if Rails.env.development? && error.respond_to?(:backtrace) flash[:error] = if error.is_a?(PgSqlTriggers::Error) format_error_for_flash(error) else "An unexpected error occurred: #{error.}" end end |