Sha256: 70ed1f53f4cce33b2ad62d9ea297456a2a5eac9dca973afa79d53dcc55cf8554

Contents?: true

Size: 1.1 KB

Versions: 5

Compression:

Stored size: 1.1 KB

Contents

module YogiBerra
  class ExceptionMiddleware
    def initialize(app)
      @app = app
      YogiBerra::Catcher.quick_connection
    end

    def call(env)
      begin
        path_parameters = env['action_controller.request.path_parameters'] || {}
        query_hash      = env['rack.request.query_hash'] || {}
        response = dup._call(env)
        environment = {
          :session => env['rack.session'],
          :params => path_parameters.merge(query_hash),
          :user_agent => env['HTTP_USER_AGENT'],
          :server_name => env['SERVER_NAME'],
          :server_port => env['SERVER_PORT'],
          :server_address => env['SERVER_ADDR'],
          :remote_address => env['REMOTE_ADDR']
        }
      rescue Exception => raised
        YogiBerra.exceptionize(raised, environment)
        raise raised
      end

      if env['rack.exception']
        YogiBerra.exceptionize(raised, environment)
      end
      response
    end

    def _call(env)
      @status, @headers, @response = @app.call(env)
      [@status, @headers, self]
    end

    def each(&block)
      @response.each(&block)
    end

  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
yogi_berra-0.0.10 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.9 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.8 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.6 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.4 lib/yogi_berra/exception_middleware.rb