Navigation Menu

Skip to content

Commit

Permalink
don't send notifications on RoutingErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
jamis committed Feb 23, 2007
1 parent e8bb7f7 commit a47be04
Showing 1 changed file with 38 additions and 29 deletions.
67 changes: 38 additions & 29 deletions lib/exception_notifiable.rb
Expand Up @@ -48,43 +48,52 @@ def exception_data(deliverer=self)
end
end

def local_request?
remote = IPAddr.new(request.remote_ip)
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end
private

def render_404
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
type.all { render :nothing => true, :status => "404 Not Found" }
def local_request?
remote = IPAddr.new(request.remote_ip)
!self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil?
end
end

def render_500
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" }
type.all { render :nothing => true, :status => "500 Error" }
def render_404
respond_to do |type|
type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" }
type.all { render :nothing => true, :status => "404 Not Found" }
end
end

def render_500
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
end

def rescue_action_in_public(exception)
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction
render_404
def rescue_action_in_public(exception)
case exception
when *exceptions_to_treat_as_404
render_404

else
render_500
else
render_500

deliverer = self.class.exception_data
data = case deliverer
when nil then {}
when Symbol then send(deliverer)
when Proc then deliverer.call(self)
end
deliverer = self.class.exception_data
data = case deliverer
when nil then {}
when Symbol then send(deliverer)
when Proc then deliverer.call(self)
end

ExceptionNotifier.deliver_exception_notification(exception, self,
request, data)
ExceptionNotifier.deliver_exception_notification(exception, self,
request, data)
end
end
end

def exceptions_to_treat_as_404
exceptions = [ActiveRecord::RecordNotFound,
ActionController::UnknownController,
ActionController::UnknownAction]
exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError)
exceptions
end
end

0 comments on commit a47be04

Please sign in to comment.