Module: Lipsiadmin::Controller::Rescue
- Defined in:
- lib/controller/rescue.rb
Overview
This module are raised when an exception fire up in controllers.
Now you can personalize exception and simplify the layout using templates in:
app/views/exception
when an exception is raised it try to send an email, and for send an email you need to configure in enviroment or in an initializer some like this:
Examples:
Lipsiadmin::Mailer::ExceptionNotifier.sender_address = %("Exception Notifier" <[email protected]>)
Lipsiadmin::Mailer::ExceptionNotifier.recipients_addresses = %([email protected])
Lipsiadmin::Mailer::ExceptionNotifier.email_prefix = "[Your Project]"
Class Method Summary collapse
-
.included(base) ⇒ Object
:nodoc:.
Instance Method Summary collapse
-
#rescue_action_in_public_with_notifier(exception) ⇒ Object
Overwrite to implement public exception handling (for requests answering false to
local_request?
).
Class Method Details
.included(base) ⇒ Object
:nodoc:
20 21 22 23 24 |
# File 'lib/controller/rescue.rb', line 20 def self.included(base)#:nodoc: base.class_eval do alias_method_chain :rescue_action_in_public, :notifier end end |
Instance Method Details
#rescue_action_in_public_with_notifier(exception) ⇒ Object
Overwrite to implement public exception handling (for requests answering false to local_request?
). By default will call render_optional_error_file. Override this method to provide more user friendly error messages.
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/controller/rescue.rb', line 28 def rescue_action_in_public_with_notifier(exception) #:doc: response_code = response_code_for_rescue(exception) status = interpret_status(response_code)[0,3] respond_to do |format| # Personalize rescue rules for backend if controller_path =~ /^backend\// # Usually when we made a post we submit the form # to a target iframe, so we need to respond to the parent. if request.post? responds_to_parent do render :update do |page| page.unmask page.ext_alert I18n.t("lipsiadmin.exceptions.#{status}.title"), I18n.t("lipsiadmin.exceptions.#{status}.description") end end else # We can't use status, because Backend.app.load don't permit load 500, 404 pages format.html { render :template => "/exceptions/#{status}" } format.js do render :update do |page| page.unmask page.ext_alert I18n.t("lipsiadmin.exceptions.#{status}.title"), I18n.t("lipsiadmin.exceptions.#{status}.description") end end format.all { render :nothing => true, :status => status } end else format.html { render :template => "/exceptions/#{status}", :status => status } format.all { render :nothing => true, :status => status } end end rescue Exception => e logger.error e. erase_results rescue_action_in_public_without_notifier(exception) ensure if response_code != :not_found && Lipsiadmin::Mailer::ExceptionNotifier.send_mail Lipsiadmin::Mailer::ExceptionNotifier.deliver_exception(exception, self, request) end end |