Class: Aranea::Rack::FailureCreator

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

Instance Method Summary collapse

Constructor Details

#initialize(app, config = {}) ⇒ FailureCreator

Returns a new instance of FailureCreator.



10
11
12
13
# File 'lib/aranea/rack/aranea_middleware.rb', line 10

def initialize(app, config = {})
  @app = app
  @config = config
end

Instance Method Details

#call(env) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/aranea/rack/aranea_middleware.rb', line 15

def call(env)
  if failure_creation_request?(env)
    response = begin
      [create_failure(::Rack::Utils.parse_query(env["QUERY_STRING"])), 201, {}]
    rescue FailureFailure => e
      [e.message, 422, {}]
    rescue => e
      [e.message, 500, {}]
    end
    ::Rack::Response.new(*response).finish
  else
    @app.call(env)
  end
end