Skip to content

Instantly share code, notes, and snippets.

@dmons
Created May 28, 2013 08:41
Show Gist options
  • Save dmons/5661389 to your computer and use it in GitHub Desktop.
Save dmons/5661389 to your computer and use it in GitHub Desktop.
Integration ExceptionNotification into app
if Rails.env.production?
rescue_from Exception, with: :render_500
rescue_from ActiveRecord::RecordNotFound, ActionController::RoutingError, :with => :render_404
else
rescue_from ActiveRecord::RecordInvalid, :with => :show_errors
end
def render_500(exception)
respond_to do |format|
ExceptionNotifier::Notifier.exception_notification(request.env, exception).deliver
format.html { render :layout=>'500',:nothing => true, status: 500 }
format.all { render nothing: true, status: 500}
end
end
def show_errors(e)
I18n.with_locale(:en) do
e.record.valid?
raise e.record.errors.full_messages.join("\n ")
end
end
gem 'exception_notification', :require => 'exception_notifier'
config.middleware.use ExceptionNotifier,
:email_prefix => "[StyleUp Exception ] ",
:sender_address => %{"styleup_bot" <no_reply@styleup.ua>},
:exception_recipients => %w{some_mail@gmail.com another_mail@gmail.com}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment