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, 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



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

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

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

Yields:



17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/rails_exception_handler.rb', line 17

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 = true
  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
# File 'lib/rails_exception_handler.rb', line 7

def call(env)
  @app.call(env)
rescue Exception => e
  Handler.new(env, e).handle_exception
end