forked from rails/web-console
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use Module#prepend when defined instead of alias_method
- Loading branch information
Showing
1 changed file
with
37 additions
and
13 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,20 +1,44 @@ | ||
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' | ||
|
||
# Get the original exception if ExceptionWrapper decides to follow it. | ||
env['web_console.exception'] = error | ||
module RenderExceptionsWithWebConsole | ||
def render_exception(env, exception) | ||
super.tap do | ||
error = ActionDispatch::ExceptionWrapper.new(env, exception).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 | ||
# 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 | ||
end | ||
end | ||
end | ||
end | ||
|
||
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 | ||
|
||
alias_method :render_exception_without_web_console, :render_exception | ||
alias_method :render_exception, :render_exception_with_web_console | ||
end |