Module: Reactive::Mvc::Controller::Rescue
- Defined in:
- lib/reactive-mvc/controller/rescue.rb
Overview
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.
Custom rescue behavior is achieved by overriding the rescue_action
method.
Defined Under Namespace
Modules: ClassMethods
Constant Summary collapse
- DEFAULT_RESCUE_RESPONSE =
:internal_server_error
- DEFAULT_RESCUE_RESPONSES =
{ 'Reactive::Mvc::Controller::UnknownAction' => :not_found, 'ActiveRecord::RecordNotFound' => :not_found, 'ActiveRecord::StaleObjectError' => :conflict, 'ActiveRecord::RecordInvalid' => :unprocessable_entity, 'ActiveRecord::RecordNotSaved' => :unprocessable_entity, 'Reactive::Mvc::Controller::MethodNotAllowed' => :method_not_allowed, 'Reactive::Mvc::Controller::NotImplemented' => :not_implemented, }
- DEFAULT_RESCUE_TEMPLATE =
'diagnostics'
- DEFAULT_RESCUE_TEMPLATES =
{ 'Reactive::Mvc::View::MissingTemplate' => 'missing_template', 'Reactive::Mvc::Controller::UnknownAction' => 'unknown_action', 'Reactive::Mvc::View::TemplateError' => 'template_error' }
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Class Method Details
.included(base) ⇒ Object
:nodoc:
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/reactive-mvc/controller/rescue.rb', line 29 def self.included(base) #:nodoc: base.cattr_accessor :rescue_responses base.rescue_responses = Hash.new(DEFAULT_RESCUE_RESPONSE) base.rescue_responses.update DEFAULT_RESCUE_RESPONSES base.cattr_accessor :rescue_templates base.rescue_templates = Hash.new(DEFAULT_RESCUE_TEMPLATE) base.rescue_templates.update DEFAULT_RESCUE_TEMPLATES base.class_inheritable_array :rescue_handlers base.rescue_handlers = [] base.extend(ClassMethods) base.class_eval do alias_method_chain :perform_action, :rescue end end |