forked from gsamokovarov/web-console
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use prepend when defined instead of alias_method_chain
This is to get the ball rolling on upgrading to Module#prepend, since `alias_method_chain` is deprecated in Rails 5.0. This PR is probably not an ideal implementation. A simpler migration would be to replace alias_method_chain with two alias_methods. Opening the discussion…
- Loading branch information
Showing
1 changed file
with
33 additions
and
12 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,40 @@ | ||
ActionDispatch::DebugExceptions.class_eval do | ||
def render_exception_with_web_console(env, exception) | ||
render_exception_without_web_console(env, exception).tap do | ||
error = ActionDispatch::ExceptionWrapper.new(env, exception).exception | ||
if defined?(Module.prepend) && Rails.version >= '4' | ||
module RenderExceptionsWithWebConsole | ||
def render_exception(env, exception) | ||
super.tap do | ||
error = ActionDispatch::ExceptionWrapper.new(env, exception).exception | ||
|
||
# Get the original exception if ExceptionWrapper decides to follow it. | ||
env['web_console.exception'] = error | ||
# Get the original exception if ExceptionWrapper decides to follow it. | ||
env['web_console.exception'] = error | ||
|
||
# ActionView::Template::Error bypass ExceptionWrapper original | ||
# exception following. The backtrace in the view is generated from | ||
# reaching out to original_exception in the view. | ||
if error.is_a?(ActionView::Template::Error) | ||
env['web_console.exception'] = error.original_exception | ||
# ActionView::Template::Error bypass ExceptionWrapper original | ||
# exception following. The backtrace in the view is generated from | ||
# reaching out to original_exception in the view. | ||
if error.is_a?(ActionView::Template::Error) | ||
env['web_console.exception'] = error.original_exception | ||
end | ||
end | ||
end | ||
end | ||
|
||
alias_method_chain :render_exception, :web_console | ||
module ActionDispatch | ||
class DebugExceptions | ||
prepend RenderExceptionsWithWebConsole | ||
end | ||
end | ||
else | ||
# Legacy code that duplicates the module above, using `alias_method_chain`. | ||
# TODO: Remove me when support for Ruby < 2 && Rails < 4 is dropped. | ||
ActionDispatch::DebugExceptions.class_eval do | ||
def render_exception_with_web_console(env, exception) | ||
render_exception_without_web_console(env, exception).tap do | ||
error = ActionDispatch::ExceptionWrapper.new(env, exception).exception | ||
env['web_console.exception'] = error | ||
if error.is_a?(ActionView::Template::Error) | ||
env['web_console.exception'] = error.original_exception | ||
end | ||
end | ||
end | ||
alias_method_chain :render_exception, :web_console | ||
end | ||
end |