Skip to content

Instantly share code, notes, and snippets.

@ephekt
Created February 2, 2012 22:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ephekt/1726144 to your computer and use it in GitHub Desktop.
Save ephekt/1726144 to your computer and use it in GitHub Desktop.
exception handling
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