Skip to content

Commit 5208509

Browse files
committed
Use ActionDispatch to get the HTTP status code for the exception
* When ActionDispatch::ExceptionWrapper is available, use it to grab the exception's status code, return a 500 otherwise. * Update show_error_page to accept the caught exception * Send show_error_page the exception
1 parent 6fe4d04 commit 5208509

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

lib/better_errors/middleware.rb

+8-3
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ def protected_app_call(env)
8585
rescue Exception => ex
8686
@error_page = @handler.new ex, env
8787
log_exception
88-
show_error_page(env)
88+
show_error_page(env, ex)
8989
end
9090

91-
def show_error_page(env)
91+
def show_error_page(env, exception=nil)
9292
type, content = if @error_page
9393
if text?(env)
9494
[ 'plain', @error_page.render('text') ]
@@ -99,7 +99,12 @@ def show_error_page(env)
9999
[ 'html', no_errors_page ]
100100
end
101101

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]]
103108
end
104109

105110
def text?(env)

0 commit comments

Comments
 (0)