Skip to content

Commit

Permalink
Merge pull request #422 from nateberkopec/rails-fix-multi-exception
Browse files Browse the repository at this point in the history
WIP: Fix Rails multi-exception reports
  • Loading branch information
nateberkopec committed Jan 6, 2016
2 parents 9108e36 + 037baab commit 2a23c63
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 20 deletions.
3 changes: 1 addition & 2 deletions lib/raven/integrations/rack.rb
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,7 @@ def call(env)
raise
end

error = env['rack.exception'] || env['sinatra.error'] || env['action_dispatch.exception']

error = env['rack.exception'] || env['sinatra.error']
Raven::Rack.capture_exception(error, env) if error

response
Expand Down
16 changes: 0 additions & 16 deletions spec/raven/integrations/rack_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -46,22 +46,6 @@
stack.call(env)
end

it 'should capture rails errors when ActionDispatch::ShowExceptions is enabled' do
exception = build_exception
env = {}

expect(Raven::Rack).to receive(:capture_exception).with(exception, env)

app = lambda do |e|
e['action_dispatch.exception'] = exception
[200, {}, ['okay']]
end

stack = Raven::Rack.new(app)

stack.call(env)
end

it 'should clear context after app is called' do
Raven::Context.current.tags[:environment] = :test

Expand Down
18 changes: 16 additions & 2 deletions spec/raven/integrations/rails_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,31 @@
config.dsn = 'dummy://notaserver'
config.encoding = 'json'
end

Rails.env = "production"
TestApp.initialize!
end

after(:each) do
Raven.client.transport.events = []
end

it "inserts middleware" do
expect(TestApp.middleware).to include(Raven::Rack)
end

pending "should capture exceptions" do
it "should capture exceptions in production" do
get "/exception"
expect(response.status).to eq(500)
expect(Raven.client.transport.events.size).to eq(1)
end

it "should properly set the exception's URL" do
get "/exception"

# TODO: dummy transport shouldn't even encode the event
event = Raven.client.transport.events.first
event = JSON.parse!(event[1])

expect(event['request']['url']).to eq("http://www.example.com/exception")
end
end

0 comments on commit 2a23c63

Please sign in to comment.