File tree 3 files changed +21
-5
lines changed
3 files changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -85,10 +85,10 @@ def protected_app_call(env)
85
85
rescue Exception => ex
86
86
@error_page = @handler . new ex , env
87
87
log_exception
88
- show_error_page ( env )
88
+ show_error_page ( env , ex )
89
89
end
90
90
91
- def show_error_page ( env )
91
+ def show_error_page ( env , exception = nil )
92
92
type , content = if @error_page
93
93
if text? ( env )
94
94
[ 'plain' , @error_page . render ( 'text' ) ]
@@ -99,7 +99,12 @@ def show_error_page(env)
99
99
[ 'html' , no_errors_page ]
100
100
end
101
101
102
- [ 500 , { "Content-Type" => "text/#{ type } ; charset=utf-8" } , [ content ] ]
102
+ status_code = 500
103
+ if defined? ActionDispatch ::ExceptionWrapper
104
+ status_code = ActionDispatch ::ExceptionWrapper . new ( env , exception ) . status_code
105
+ end
106
+
107
+ [ status_code , { "Content-Type" => "text/#{ type } ; charset=utf-8" } , [ content ] ]
103
108
end
104
109
105
110
def text? ( env )
Original file line number Diff line number Diff line change 1
1
module BetterErrors
2
- VERSION = "0.9.0 "
2
+ VERSION = "0.10.0.pre "
3
3
end
Original file line number Diff line number Diff line change 3
3
module BetterErrors
4
4
describe Middleware do
5
5
let ( :app ) { Middleware . new ( -> env { ":)" } ) }
6
+ let ( :exception ) { RuntimeError . new ( "oh no :(" ) }
6
7
7
8
it "should pass non-error responses through" do
8
9
app . call ( { } ) . should == ":)"
@@ -54,14 +55,24 @@ module BetterErrors
54
55
end
55
56
56
57
context "when handling an error" do
57
- let ( :app ) { Middleware . new ( -> env { raise "oh no :(" } ) }
58
+ let ( :app ) { Middleware . new ( -> env { raise exception } ) }
58
59
59
60
it "should return status 500" do
60
61
status , headers , body = app . call ( { } )
61
62
62
63
status . should == 500
63
64
end
64
65
66
+ it "should return ExceptionWrapper's status_code" do
67
+ ad_ew = double ( "ActionDispatch::ExceptionWrapper" )
68
+ ad_ew . stub ( 'new' ) . with ( { } , exception ) { double ( "ExceptionWrapper" , status_code : 404 ) }
69
+ stub_const ( 'ActionDispatch::ExceptionWrapper' , ad_ew )
70
+
71
+ status , headers , body = app . call ( { } )
72
+
73
+ status . should == 404
74
+ end
75
+
65
76
it "should return UTF-8 error pages" do
66
77
status , headers , body = app . call ( { } )
67
78
You can’t perform that action at this time.
0 commit comments