Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add public API to set last error #352

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 18 additions & 1 deletion lib/better_errors/middleware.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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
Expand Down