Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract ActionController rescue templates into Rescue and ShowExcepti…
…ons middleware. This commit breaks all exception catching plugins like ExceptionNotifier. These plugins should be rewritten as middleware instead overriding Controller#rescue_action_in_public.
- Loading branch information
Showing
28 changed files
with
403 additions
and
556 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
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
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 |
---|---|---|
@@ -0,0 +1,50 @@ | ||
module ActionController #:nodoc: | ||
# Actions that fail to perform as expected throw exceptions. These | ||
# exceptions can either be rescued for the public view (with a nice | ||
# user-friendly explanation) or for the developers view (with tons of | ||
# debugging information). The developers view is already implemented by | ||
# the Action Controller, but the public view should be tailored to your | ||
# specific application. | ||
# | ||
# The default behavior for public exceptions is to render a static html | ||
# file with the name of the error code thrown. If no such file exists, an | ||
# empty response is sent with the correct status code. | ||
# | ||
# You can override what constitutes a local request by overriding the | ||
# <tt>local_request?</tt> method in your own controller. Custom rescue | ||
# behavior is achieved by overriding the <tt>rescue_action_in_public</tt> | ||
# and <tt>rescue_action_locally</tt> methods. | ||
module Rescue | ||
def self.included(base) #:nodoc: | ||
base.send :include, ActiveSupport::Rescuable | ||
base.extend(ClassMethods) | ||
|
||
base.class_eval do | ||
alias_method_chain :perform_action, :rescue | ||
end | ||
end | ||
|
||
module ClassMethods | ||
def rescue_action(env) | ||
exception = env.delete('action_dispatch.rescue.exception') | ||
request = ActionDispatch::Request.new(env) | ||
response = ActionDispatch::Response.new | ||
new.process(request, response, :rescue_action, exception).to_a | ||
end | ||
end | ||
|
||
protected | ||
# Exception handler called when the performance of an action raises | ||
# an exception. | ||
def rescue_action(exception) | ||
rescue_with_handler(exception) || raise(exception) | ||
end | ||
|
||
private | ||
def perform_action_with_rescue | ||
perform_action_without_rescue | ||
rescue Exception => exception | ||
rescue_action(exception) | ||
end | ||
end | ||
end |
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
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
This file was deleted.
Oops, something went wrong.
10 changes: 0 additions & 10 deletions
10
actionpack/lib/action_controller/dispatch/templates/rescues/diagnostics.erb
This file was deleted.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
module ActionDispatch | ||
class Rescue | ||
def initialize(app, rescuer) | ||
@app, @rescuer = app, rescuer | ||
end | ||
|
||
def call(env) | ||
@app.call(env) | ||
rescue Exception => exception | ||
env['action_dispatch.rescue.exception'] = exception | ||
@rescuer.call(env) | ||
end | ||
end | ||
end |
Oops, something went wrong.
11af089
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So now
#local_request?
isn't as easily overridable. Is there a better place where this could be defined so it's explicitly exposed for overriding? This is what I'm using now: http://zapt.in/Ln1.