Class: Exceptify::Rack

Inherits:
Object
  • Object
show all
Defined in:
lib/exceptify/rack.rb

Defined Under Namespace

Classes: CascadePassException

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Rack

Returns a new instance of Rack.



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/exceptify/rack.rb', line 11

def initialize(app, options = {})
  @app = app
  @dispatcher = options.delete(:dispatcher)
  @configuration = options.delete(:configuration)
  @ignore_cascade_pass = options.delete(:ignore_cascade_pass) { true }

  return if @dispatcher
  return if options.empty? && @configuration.nil?

  @configuration ||= Exceptify.configuration.copy
  apply_options(@configuration, options)
  @dispatcher = Dispatcher.new(@configuration)
end

Instance Attribute Details

#configurationObject (readonly)

Returns the value of attribute configuration.



9
10
11
# File 'lib/exceptify/rack.rb', line 9

def configuration
  @configuration
end

Instance Method Details

#call(env) ⇒ Object



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

def call(env)
  _, headers, = response = @app.call(env)

  if !@ignore_cascade_pass && headers["X-Cascade"] == "pass"
    msg = "This exception means that the preceding Rack middleware set the 'X-Cascade' header to 'pass' -- in " \
          "Rails, this often means that the route was not found (404 error)."
    raise CascadePassException, msg
  end

  response
rescue Exception => e # standard:disable Lint/RescueException
  env["exceptify.delivered"] = true if dispatcher.notify_exception(e, env: env)

  raise e unless e.is_a?(CascadePassException)

  response
end