class RailsExceptionHandler

Public Class Methods

catch(&block) click to toggle source
# File lib/rails_exception_handler/catcher.rb, line 3
def self.catch(&block)
  begin
    block.call
  rescue Exception => exception
    if(configuration.activate?)
      exception_handler = Handler.new({'REQUEST_METHOD' => "GET", "rack.input" => ""}, exception)
      exception_handler.handle_exception
    else
      raise exception
    end
  end
end
configuration() click to toggle source
# File lib/rails_exception_handler.rb, line 14
def self.configuration
  @configuration ||= Configuration.new
end
configure() { |configuration| ... } click to toggle source
# File lib/rails_exception_handler.rb, line 18
def self.configure
  yield configuration
  return unless configuration.activate?

  unless Rails.configuration.middleware.class == ActionDispatch::MiddlewareStack && Rails.configuration.middleware.include?(RailsExceptionHandler)
    Rails.configuration.middleware.use(RailsExceptionHandler)
  end


  Rails.configuration.action_dispatch.show_exceptions = if Rails::VERSION::MAJOR < 7 || (Rails::VERSION::MAJOR == 7 && Rails::VERSION::MINOR == 0)
    true
  else
    :all
  end
  Rails.configuration.consider_all_requests_local = false
  require File.expand_path(File.dirname(__FILE__)) + '/patch/show_exceptions.rb'
  configuration.run_callback
end
new(app) click to toggle source
# File lib/rails_exception_handler.rb, line 3
def initialize(app)
  @app = app
end

Public Instance Methods

call(env) click to toggle source
# File lib/rails_exception_handler.rb, line 7
def call(env)
  @app.call(env)
rescue Exception => e
  raise e unless RailsExceptionHandler.configuration.activate?
  Handler.new(env, e).handle_exception
end