Sha256: d42a82dceec0058cbc21d7f56e549068cb0b2ab8c32b4f4115d89522d1543fd2

Contents?: true

Size: 1.24 KB

Versions: 11

Compression:

Stored size: 1.24 KB

Contents

module Nadir
  module Middleware
    class Rack
      def initialize(app)
        @app = app
      end

      def call(env)
        begin
          response = @app.call(env)
        rescue Exception => exception
          begin
            request = ActionDispatch::Request.new env

            headers = request.headers.env.select{|k, _| k.in?(ActionDispatch::Http::Headers::CGI_VARIABLES) || k =~ /^HTTP_/}
            location = request.parameters.values_at('controller', 'action').compact.join('#')
            location = location.presence || "#{headers['REQUEST_METHOD']} #{headers['PATH_INFO']}"

            request_params = {
              headers: headers,
              params: request.parameters,
              remote_ip: request.remote_ip,
              user: {}
            }

            if request.env['warden'] && request.env['warden'].respond_to?(:user)
              request_params[:user][:id] = request.env['warden'].user&.id
            end

            Nadir.notify exception, location: location, request: request_params
          rescue => e
            Nadir.logger.error "[Nadir] Internal error: #{e.inspect}"
          end

          raise
        end

        response
      ensure
        # Nadir.clear_request_data
      end
    end
  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
nadir-1.2.1 lib/nadir/middleware/rack.rb
nadir-1.2.0 lib/nadir/middleware/rack.rb
nadir-1.1.10 lib/nadir/middleware/rack.rb
nadir-1.1.9 lib/nadir/middleware/rack.rb
nadir-1.1.8 lib/nadir/middleware/rack.rb
nadir-1.1.7 lib/nadir/middleware/rack.rb
nadir-1.1.6 lib/nadir/middleware/rack.rb
nadir-1.1.5 lib/nadir/middleware/rack.rb
nadir-1.1.4 lib/nadir/middleware/rack.rb
nadir-1.1.3 lib/nadir/middleware/rack.rb
nadir-1.1.2 lib/nadir/middleware/rack.rb