From 59a71d4b0645a794758879b467b902b1dd5c3619 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 10 Aug 2016 17:29:12 +0900 Subject: [PATCH 1/2] Add public API to set last error --- lib/better_errors/middleware.rb | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/lib/better_errors/middleware.rb b/lib/better_errors/middleware.rb index 5362f3cc..ce4df525 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 ex, env + log_exception + end + end + rescue Exception => ex @error_page = @handler.new ex, env log_exception From 94811e029e2b8f99b798a2eb219f33c8b96681c3 Mon Sep 17 00:00:00 2001 From: Ryo Onodera Date: Wed, 10 Aug 2016 17:36:53 +0900 Subject: [PATCH 2/2] Fix typo... --- lib/better_errors/middleware.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/better_errors/middleware.rb b/lib/better_errors/middleware.rb index ce4df525..75306043 100644 --- a/lib/better_errors/middleware.rb +++ b/lib/better_errors/middleware.rb @@ -94,7 +94,7 @@ def protected_app_call(env) @app.call(env).tap do error = BetterErrors.take_last_error if error - @error_page = @handler.new ex, env + @error_page = @handler.new error, env log_exception end end