Created
February 2, 2012 22:15
-
-
Save ephekt/1726144 to your computer and use it in GitHub Desktop.
exception handling
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
Model: | |
class ExceptionMailer < ActionMailer::Base | |
def exception_notification(ex, request, sent_at = Time.now) | |
subject "Answerwise Exception: #{ex.class} - #{ex.message}" | |
recipients 'mfrosengarten@gmail.com' | |
from 'mfrosengarten@gmail.com' | |
sent_on sent_at | |
body :exception_message => ex.to_s, | |
:exception_class => ex.class, | |
:request => request, | |
:backtrace => ex.backtrace.join("<br />") if ex.backtrace | |
end | |
end | |
(http://apidock.com/rails/ActionController/Rescue/rescue_action_in_public) | |
In ApplicationController: | |
def rescue_action_in_public(exception) | |
ExceptionMailer.deliver_exception_notification(exception,request) | |
case exception | |
when *self.class.exceptions_to_treat_as_404 | |
respond_to do |format| | |
format.html {render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Error"} | |
format.all { render :nothing => true, :status => "404 Error"} | |
end | |
else | |
respond_to do |type| | |
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } | |
type.all { render :nothing => true, :status => "500 Error" } | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment