Changeset 6216
- Timestamp:
- 02/23/07 19:30:38 (2 years ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
plugins/exception_notification/lib/exception_notifiable.rb
r3900 r6216 49 49 end 50 50 51 def local_request? 52 remote = IPAddr.new(request.remote_ip) 53 !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil? 54 end 51 private 55 52 56 def render_404 57 respond_to do |type| 58 type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } 59 type.all { render :nothing => true, :status => "404 Not Found" } 53 def local_request? 54 remote = IPAddr.new(request.remote_ip) 55 !self.class.local_addresses.detect { |addr| addr.include?(remote) }.nil? 60 56 end 61 end62 57 63 def render_500 64 respond_to do |type| 65 type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } 66 type.all { render :nothing => true, :status => "500 Error" } 58 def render_404 59 respond_to do |type| 60 type.html { render :file => "#{RAILS_ROOT}/public/404.html", :status => "404 Not Found" } 61 type.all { render :nothing => true, :status => "404 Not Found" } 62 end 67 63 end 68 end69 64 70 def rescue_action_in_public(exception) 71 case exception 72 when ActiveRecord::RecordNotFound, ActionController::UnknownController, ActionController::UnknownAction 73 render_404 65 def render_500 66 respond_to do |type| 67 type.html { render :file => "#{RAILS_ROOT}/public/500.html", :status => "500 Error" } 68 type.all { render :nothing => true, :status => "500 Error" } 69 end 70 end 74 71 75 else 76 render_500 72 def rescue_action_in_public(exception) 73 case exception 74 when *exceptions_to_treat_as_404 75 render_404 77 76 78 deliverer = self.class.exception_data 79 data = case deliverer 80 when nil then {} 81 when Symbol then send(deliverer) 82 when Proc then deliverer.call(self) 83 end 77 else 78 render_500 84 79 85 ExceptionNotifier.deliver_exception_notification(exception, self, 86 request, data) 80 deliverer = self.class.exception_data 81 data = case deliverer 82 when nil then {} 83 when Symbol then send(deliverer) 84 when Proc then deliverer.call(self) 85 end 86 87 ExceptionNotifier.deliver_exception_notification(exception, self, 88 request, data) 89 end 87 90 end 88 end89 91 92 def exceptions_to_treat_as_404 93 exceptions = [ActiveRecord::RecordNotFound, 94 ActionController::UnknownController, 95 ActionController::UnknownAction] 96 exceptions << ActionController::RoutingError if ActionController.const_defined?(:RoutingError) 97 exceptions 98 end 90 99 end