Skip to content

Commit 3cdae1d

Browse files
committed
Merge pull request #461 from eugeneius/debug_middleware_response
Return original response in debug middleware patch
2 parents b793380 + 0bbe600 commit 3cdae1d

File tree

2 files changed

+83
-6
lines changed

2 files changed

+83
-6
lines changed

lib/raven/integrations/rails/middleware/debug_exceptions_catcher.rb

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,11 @@ class Rails
33
module Middleware
44
module DebugExceptionsCatcher
55
def render_exception(env_or_request, exception)
6-
env = env_or_request.respond_to?(:env) ? env_or_request.env : env_or_request
7-
Raven::Rack.capture_exception(exception, env)
8-
ensure
6+
begin
7+
env = env_or_request.respond_to?(:env) ? env_or_request.env : env_or_request
8+
Raven::Rack.capture_exception(exception, env)
9+
rescue # rubocop:disable Lint/HandleExceptions
10+
end
911
super
1012
end
1113
end
@@ -16,9 +18,11 @@ def self.included(base)
1618
end
1719

1820
def render_exception_with_raven(env_or_request, exception)
19-
env = env_or_request.respond_to?(:env) ? env_or_request.env : env_or_request
20-
Raven::Rack.capture_exception(exception, env)
21-
ensure
21+
begin
22+
env = env_or_request.respond_to?(:env) ? env_or_request.env : env_or_request
23+
Raven::Rack.capture_exception(exception, env)
24+
rescue # rubocop:disable Lint/HandleExceptions
25+
end
2226
render_exception_without_raven(env_or_request, exception)
2327
end
2428
end
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
require 'spec_helper'
2+
require 'raven/integrations/rails/middleware/debug_exceptions_catcher'
3+
4+
describe Raven::Rails::Middleware::DebugExceptionsCatcher do
5+
let(:middleware) do
6+
Class.new do
7+
def initialize(app)
8+
@app = app
9+
end
10+
11+
def call(env)
12+
@app.call(env)
13+
rescue => e
14+
render_exception(env, e)
15+
end
16+
17+
def render_exception(_, exception)
18+
[500, exception.message, {}]
19+
end
20+
end
21+
end
22+
23+
let(:app) do
24+
lambda { |_| raise "app error" } # rubocop:disable Style/Lambda
25+
end
26+
27+
let(:env) { {} }
28+
29+
context "using include" do
30+
before do
31+
middleware.send(:include, Raven::Rails::Middleware::OldDebugExceptionsCatcher)
32+
end
33+
34+
it "shows the exception" do
35+
expect(middleware.new(app).call(env)).to eq([500, "app error", {}])
36+
end
37+
38+
it "captures the exception" do
39+
expect(Raven::Rack).to receive(:capture_exception)
40+
middleware.new(app).call(env)
41+
end
42+
43+
context "when an error is raised" do
44+
it "shows the original exception" do
45+
allow(Raven::Rack).to receive(:capture_exception).and_raise("raven error")
46+
expect(middleware.new(app).call(env)).to eq([500, "app error", {}])
47+
end
48+
end
49+
end
50+
51+
context "using prepend" do
52+
before do
53+
skip "prepend not available" unless middleware.respond_to?(:prepend, true)
54+
middleware.send(:prepend, Raven::Rails::Middleware::DebugExceptionsCatcher)
55+
end
56+
57+
it "shows the exception" do
58+
expect(middleware.new(app).call(env)).to eq([500, "app error", {}])
59+
end
60+
61+
it "captures the exception" do
62+
expect(Raven::Rack).to receive(:capture_exception)
63+
middleware.new(app).call(env)
64+
end
65+
66+
context "when an error is raised" do
67+
it "shows the original exception" do
68+
allow(Raven::Rack).to receive(:capture_exception).and_raise("raven error")
69+
expect(middleware.new(app).call(env)).to eq([500, "app error", {}])
70+
end
71+
end
72+
end
73+
end

0 commit comments

Comments
 (0)