Sha256: 369bb8affc7ceebf0a2ef316a00a113242b7f417a873bf880006ce2cd9f89afd

Contents?: true

Size: 1.11 KB

Versions: 6

Compression:

Stored size: 1.11 KB

Contents

module YogiBerra
  class ExceptionMiddleware
    def initialize(app)
      @app = app
      YogiBerra::Catcher.quick_connection(true)
    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

6 entries across 6 versions & 1 rubygems

Version Path
yogi_berra-0.0.15 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.14 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.13 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.12 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.11 lib/yogi_berra/exception_middleware.rb
yogi_berra-0.0.5 lib/yogi_berra/exception_middleware.rb