Class: RailsExceptionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/rails_exception_handler.rb,
lib/rails_exception_handler/engine.rb,
lib/rails_exception_handler/catcher.rb,
lib/generators/rails_exception_handler/install_generator.rb

Defined Under Namespace

Classes: ActiveRecord, Configuration, Engine, ErrorMailer, FakeSession, Handler, InstallGenerator, Mongoid, Parser, Storage

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ RailsExceptionHandler

Returns a new instance of RailsExceptionHandler.



3
4
5
# File 'lib/rails_exception_handler.rb', line 3

def initialize(app)
  @app = app
end

Class Method Details

.catch(&block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
# 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

.configurationObject



14
15
16
# File 'lib/rails_exception_handler.rb', line 14

def self.configuration
  @configuration ||= Configuration.new
end

.configure {|configuration| ... } ⇒ Object

Yields:



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# 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

Instance Method Details

#call(env) ⇒ Object



7
8
9
10
11
12
# 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