diff --git a/lib/better_errors/middleware.rb b/lib/better_errors/middleware.rb index 5362f3cc..75306043 100644 --- a/lib/better_errors/middleware.rb +++ b/lib/better_errors/middleware.rb @@ -4,6 +4,16 @@ require "rack" module BetterErrors + def self.set_last_error(error) + @last_error = error + end + + def self.take_last_error + error = @last_error + @last_error = nil + error + end + # Better Errors' error handling middleware. Including this in your middleware # stack will show a Better Errors error page for exceptions raised below this # middleware. @@ -81,7 +91,14 @@ def better_errors_call(env) end def protected_app_call(env) - @app.call env + @app.call(env).tap do + error = BetterErrors.take_last_error + if error + @error_page = @handler.new error, env + log_exception + end + end + rescue Exception => ex @error_page = @handler.new ex, env log_exception