File tree 4 files changed +65
-1
lines changed
4 files changed +65
-1
lines changed Original file line number Diff line number Diff line change @@ -11,7 +11,11 @@ class ErrorHandler
11
11
def self . call e , request , response
12
12
logger . error e
13
13
logger . error e . backtrace
14
- response . body = { :message => e . message , :backtrace => e . backtrace } . to_json
14
+ response_body = { :message => e . message }
15
+ if PactBroker . configuration . show_backtrace_in_error_response?
16
+ response_body [ :backtrace ] = e . backtrace
17
+ end
18
+ response . body = response_body . to_json
15
19
report ( e , request ) if reportable? ( e )
16
20
end
17
21
Original file line number Diff line number Diff line change @@ -91,6 +91,10 @@ def self.default_html_pact_render
91
91
}
92
92
end
93
93
94
+ def show_backtrace_in_error_response?
95
+ !!( ENV [ 'RACK_ENV' ] && ENV [ 'RACK_ENV' ] . downcase != 'production' )
96
+ end
97
+
94
98
def authentication_configured?
95
99
!!authenticate || !!authenticate_with_basic_auth
96
100
end
Original file line number Diff line number Diff line change @@ -40,6 +40,32 @@ module Resources
40
40
end
41
41
end
42
42
43
+ context "when show_backtrace_in_error_response? is true" do
44
+ before do
45
+ allow ( PactBroker . configuration ) . to receive ( :show_backtrace_in_error_response? ) . and_return ( true )
46
+ end
47
+
48
+ it "includes the backtrace in the error response" do
49
+ expect ( response ) . to receive ( :body= ) do | body |
50
+ expect ( body ) . to include ( "backtrace" )
51
+ end
52
+ subject
53
+ end
54
+ end
55
+
56
+ context "when show_backtrace_in_error_response? is false" do
57
+ before do
58
+ allow ( PactBroker . configuration ) . to receive ( :show_backtrace_in_error_response? ) . and_return ( false )
59
+ end
60
+
61
+ it "does not include the backtrace in the error response" do
62
+ expect ( response ) . to receive ( :body= ) do | body |
63
+ expect ( body ) . to_not include ( "backtrace" )
64
+ end
65
+ subject
66
+ end
67
+ end
68
+
43
69
context "when the error is a PactBroker::TestError" do
44
70
let ( :error ) { PactBroker ::TestError . new ( 'test error' ) }
45
71
Original file line number Diff line number Diff line change 6
6
module PactBroker
7
7
describe Configuration do
8
8
9
+ describe "show_backtrace_in_error_response?" do
10
+ before do
11
+ allow ( ENV ) . to receive ( :[] ) . and_call_original
12
+ end
13
+
14
+ context "when RACK_ENV is not set" do
15
+ before do
16
+ allow ( ENV ) . to receive ( :[] ) . with ( "RACK_ENV" ) . and_return ( nil )
17
+ end
18
+
19
+ its ( :show_backtrace_in_error_response? ) { is_expected . to be false }
20
+ end
21
+
22
+ context "when RACK_ENV is not production" do
23
+ before do
24
+ allow ( ENV ) . to receive ( :[] ) . with ( "RACK_ENV" ) . and_return ( 'development' )
25
+ end
26
+
27
+ its ( :show_backtrace_in_error_response? ) { is_expected . to be true }
28
+ end
29
+
30
+ context "when RACK_ENV is production" do
31
+ before do
32
+ allow ( ENV ) . to receive ( :[] ) . with ( "RACK_ENV" ) . and_return ( 'production' )
33
+ end
34
+
35
+ its ( :show_backtrace_in_error_response? ) { is_expected . to be false }
36
+ end
37
+ end
38
+
9
39
context "default configuration" do
10
40
describe ".html_pact_renderer" do
11
41
You can’t perform that action at this time.
0 commit comments