Module: AutoError

Defined in:
lib/auto_error.rb,
lib/auto_error/config.rb,
lib/auto_error/engine.rb,
lib/auto_error/errors.rb,
lib/auto_error/version.rb,
lib/auto_error/helper_context.rb,
app/models/auto_error/app_error.rb,
lib/auto_error/context_shorthand.rb,
app/helpers/auto_error/application_helper.rb,
app/decorators/auto_error/app_error_decorator.rb

Defined Under Namespace

Modules: ApplicationHelper, Config, ContextShorthand, Errors Classes: AppError, AppErrorDecorator, AppErrorsController, ApplicationController, Engine, ErrorsController, HelperContext, MainController

Constant Summary collapse

VERSION =
"0.0.14"

Class Method Summary collapse

Class Method Details

.setup!(app_config) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/auto_error.rb', line 23

def self.setup!( app_config )
  AutoError::Config.send(:set_defaults)
  app_config.action_dispatch.rescue_responses["AutoError::Errors::Denied"] = :forbidden
  app_config.action_dispatch.rescue_responses["AutoError::Errors::NotFound"] = :not_found

  original_exceptions_app = app_config.exceptions_app || ActionDispatch::PublicExceptions.new(Rails.public_path)
  app_config.exceptions_app = ->(env) do
    puts "Handling exception for #{env['action_controller.instance'].class}"
    controller_class = env['action_controller.instance'].class
    if controller_class.nil? || AutoError.constants.any? { |c| AutoError.const_get(c) == controller_class }
      # do not log/handle exception at all if the error is actually
      # IN auto_error :)
      original_exceptions_app.call(env)
    else
      env['auto_error.original_controller.instance'] = env['action_controller.instance']
      AutoError::ErrorsController.action(:show).call(env)
    end
  end
end