Skip to content

Commit

Permalink
try to avoid using deprecated session.session_id method
Browse files Browse the repository at this point in the history
  • Loading branch information
darragh committed Oct 30, 2009
1 parent f2dbdca commit 67b4959
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 16 deletions.
4 changes: 2 additions & 2 deletions exceptional.gemspec
@@ -1,12 +1,12 @@
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{exceptional}
s.version = "0.2.0rc"
s.version = "0.1.99"
s.authors = ["Contrast"]
s.summary = %q{Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service)}
s.description = %q{Exceptional is the core Ruby library for communicating with http://getexceptional.com (hosted error tracking service). Use it to find out about errors that happen in your live app. It captures lots of helpful information to help you fix the errors.}
s.email = %q{hello@contrast.ie}
s.files = Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['spec/**/*'] + Dir['rails/**/*'] + Dir['tasks/**/*'] + Dir['*.rb']
s.files = Dir['lib/**/*'] + Dir['spec/**/*'] + Dir['spec/**/*'] + Dir['rails/**/*'] + Dir['tasks/**/*'] + Dir['*.rb'] + ["exceptional.gemspec"]
s.homepage = %q{http://getexceptional.com/}
s.require_paths = ["lib"]
s.executables << 'exceptional'
Expand Down
6 changes: 4 additions & 2 deletions lib/exceptional/catcher.rb
Expand Up @@ -2,8 +2,10 @@ module Exceptional
class Catcher
class << self
def handle(exception, controller=nil, request=nil)
data = ExceptionData.new(exception, controller, request)
Remote.error(data.to_json)
if Config.enabled?
data = ExceptionData.new(exception, controller, request)
Remote.error(data.to_json)
end
end
end
end
Expand Down
2 changes: 1 addition & 1 deletion lib/exceptional/config.rb
Expand Up @@ -65,7 +65,7 @@ def remote_port
end

def reset
@ssl_enabled = @remote_host = @remote_port = @api_key = nil
@enabled = @ssl_enabled = @remote_host = @remote_port = @api_key = nil
end

def http_open_timeout
Expand Down
8 changes: 5 additions & 3 deletions lib/exceptional/exception_data.rb
Expand Up @@ -42,7 +42,7 @@ def to_hash
'request_method' => @request.request_method.to_s,
'remote_ip' => @request.remote_ip,
'headers' => extract_http_headers(@request.env),
'session' => Exceptional::ExceptionData.sanitize_session(@request.session)
'session' => Exceptional::ExceptionData.sanitize_session(@request)
}
})
end
Expand Down Expand Up @@ -111,9 +111,11 @@ def self.sanitize_hash(hash)
{}
end

def self.sanitize_session(session)
def self.sanitize_session(request)
session = request.session
session_hash = {}
session_hash['session_id'] = session.respond_to?(:session_id) ? session.session_id : session.instance_variable_get("@session_id")
session_hash['session_id'] = request.session_options.try(:[], :id)
session_hash['session_id'] ||= session.respond_to?(:session_id) ? session.session_id : session.instance_variable_get("@session_id")
session_hash['data'] = session.respond_to?(:to_hash) ? session.to_hash : session.instance_variable_get("@data") || {}
session_hash['session_id'] ||= session_hash['data'][:session_id]
session_hash['data'].delete(:session_id)
Expand Down
10 changes: 5 additions & 5 deletions lib/exceptional/remote.rb
Expand Up @@ -12,7 +12,7 @@ def announce(json_data)
def error(json_data)
Exceptional.logger.info "Notifying Exceptional about an error"
url = "/api/errors?api_key=#{::Exceptional::Config.api_key}&protocol_version=#{::Exceptional::PROTOCOL_VERSION}"
compressed = Zlib::Deflate.deflate(json_data,Zlib::BEST_SPEED)
compressed = Zlib::Deflate.deflate(json_data, Zlib::BEST_SPEED)
call_remote(url, compressed)
end

Expand All @@ -29,10 +29,10 @@ def call_remote(url, data)
begin
response = client.post(url, data)
case response
when Net::HTTPSuccess
Exceptional.logger.info('Successful')
else
Exceptional.logger.error('Failed')
when Net::HTTPSuccess
Exceptional.logger.info('Successful')
else
Exceptional.logger.error('Failed')
end
rescue Exception => e
Exceptional.logger.error('Problem notifying Exceptional about the error')
Expand Down
13 changes: 10 additions & 3 deletions spec/exceptional/exception_data_spec.rb
Expand Up @@ -91,12 +91,19 @@ def initialize
@session_id = '123'
end
end
request = ActionController::TestRequest.new
session = SessionWithInstanceVariables.new
Exceptional::ExceptionData.sanitize_session(session).should == {'session_id' => '123', 'data' => {'a' => '1'}}
request.stub!(:session).and_return(session)
request.stub!(:session_options).and_return({})
Exceptional::ExceptionData.sanitize_session(request).should == {'session_id' => '123', 'data' => {'a' => '1'}}
session = mock('session', :session_id => '123', :instance_variable_get => {'a' => '1'})
Exceptional::ExceptionData.sanitize_session(session).should == {'session_id' => '123', 'data' => {'a' => '1'}}
request.stub!(:session).and_return(session)
Exceptional::ExceptionData.sanitize_session(request).should == {'session_id' => '123', 'data' => {'a' => '1'}}
session = mock('session', :session_id => nil, :to_hash => {:session_id => '123', 'a' => '1'})
Exceptional::ExceptionData.sanitize_session(session).should == {'session_id' => '123', 'data' => {'a' => '1'}}
request.stub!(:session).and_return(session)
Exceptional::ExceptionData.sanitize_session(request).should == {'session_id' => '123', 'data' => {'a' => '1'}}
request.stub!(:session_options).and_return({:id => 'xyz'})
Exceptional::ExceptionData.sanitize_session(request).should == {'session_id' => 'xyz', 'data' => {'a' => '1'}}
end

it "filter session cookies from headers" do
Expand Down

0 comments on commit 67b4959

Please sign in to comment.