Class: Rack::Rescue

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/rescue.rb,
lib/rack/rescue/handler.rb,
lib/rack/rescue/responder.rb,
lib/rack/rescue/exceptions.rb

Overview

Rack Middleware for rescuing exceptions and responding to the client With a page that is descriptive

Defined Under Namespace

Classes: Exceptions, Handler, Responder

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) {|@exceptions_map| ... } ⇒ Rescue

Returns a new instance of Rescue.

Yields:

  • (@exceptions_map)


33
34
35
36
37
38
39
# File 'lib/rack/rescue.rb', line 33

def initialize(app, options = {})
  @app = app
  load_defaults = options.fetch(:load_default_exceptions, true)
  @exceptions_map = Exceptions.new(load_defaults)
  @formats        = options[:formats]
  yield @exceptions_map if block_given?
end

Class Method Details

.add_handler(&blk) ⇒ Object



29
30
31
# File 'lib/rack/rescue.rb', line 29

def self.add_handler(&blk)
  error_handlers << blk
end

.default_formatsObject



19
20
21
22
23
24
25
26
27
# File 'lib/rack/rescue.rb', line 19

def self.default_formats
  return @default_formats if @default_formats

  if ENV['RACK_ENV'] == 'production'
    @default_formats = Pancake::MimeTypes.groups.keys.map(&:to_sym)
  else
    Pancake::MimeTypes.groups.keys.map(&:to_sym)
  end
end

Instance Method Details

#call(env) ⇒ Object



49
50
51
52
53
# File 'lib/rack/rescue.rb', line 49

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

#formatsObject



41
42
43
# File 'lib/rack/rescue.rb', line 41

def formats
  @formats || self.class.default_formats
end

#formats=(fmts) ⇒ Object



45
46
47
# File 'lib/rack/rescue.rb', line 45

def formats=(fmts)
  @formats = fmts
end