From 0975858cdb3430a7f717b3c972c3d6eb6e205784 Mon Sep 17 00:00:00 2001 From: Tom Hughes Date: Fri, 31 Aug 2007 10:11:15 +0000 Subject: [PATCH] Allow exceptions processing node and segment requests to propagate and be handled by the default handler so they are logged. --- app/controllers/node_controller.rb | 23 ++++++----------------- app/controllers/segment_controller.rb | 27 ++++++--------------------- app/models/node.rb | 18 ++++++------------ app/models/segment.rb | 18 ++++++------------ 4 files changed, 24 insertions(+), 62 deletions(-) diff --git a/app/controllers/node_controller.rb b/app/controllers/node_controller.rb index 5d50df7e6..4e2a9b7f2 100644 --- a/app/controllers/node_controller.rb +++ b/app/controllers/node_controller.rb @@ -13,12 +13,9 @@ class NodeController < ApplicationController if node node.user_id = @user.id node.visible = true + node.save_with_history! - if node.save_with_history - render :text => node.id.to_s, :content_type => "text/plain" - else - render :nothing => true, :status => :internal_server_error - end + render :text => node.id.to_s, :content_type => "text/plain" else render :nothing => true, :status => :bad_request end @@ -38,8 +35,6 @@ class NodeController < ApplicationController end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end @@ -55,12 +50,9 @@ class NodeController < ApplicationController node.latitude = new_node.latitude node.longitude = new_node.longitude node.tags = new_node.tags + node.save_with_history! - if node.save_with_history - render :nothing => true - else - render :nothing => true, :status => :internal_server_error - end + render :nothing => true else render :nothing => true, :status => :bad_request end @@ -69,8 +61,6 @@ class NodeController < ApplicationController end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end @@ -84,7 +74,8 @@ class NodeController < ApplicationController else node.user_id = @user.id node.visible = 0 - node.save_with_history + node.save_with_history! + render :nothing => true end else @@ -92,8 +83,6 @@ class NodeController < ApplicationController end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end diff --git a/app/controllers/segment_controller.rb b/app/controllers/segment_controller.rb index 42e939a65..b99f7460f 100644 --- a/app/controllers/segment_controller.rb +++ b/app/controllers/segment_controller.rb @@ -19,12 +19,9 @@ class SegmentController < ApplicationController segment.user_id = @user.id segment.from_node = Node.find(segment.node_a.to_i) segment.to_node = Node.find(segment.node_b.to_i) + segment.save_with_history! - if segment.save_with_history - render :text => segment.id.to_s, :content_type => "text/plain" - else - render :nothing => true, :status => :internal_server_error - end + render :text => segment.id.to_s, :content_type => "text/plain" end else render :nothing => true, :status => :bad_request @@ -45,8 +42,6 @@ class SegmentController < ApplicationController end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end @@ -68,12 +63,9 @@ class SegmentController < ApplicationController segment.node_b = new_segment.node_b segment.tags = new_segment.tags segment.visible = new_segment.visible + segment.save_with_history! - if segment.save_with_history - render :nothing => true - else - render :nothing => true, :status => :internal_server_error - end + render :nothing => true end else render :nothing => true, :status => :bad_request @@ -83,8 +75,6 @@ class SegmentController < ApplicationController end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end @@ -98,20 +88,15 @@ class SegmentController < ApplicationController else segment.user_id = @user.id segment.visible = 0 + segment.save_with_history! - if segment.save_with_history - render :nothing => true - else - render :nothing => true, :status => :internal_server_error - end + render :nothing => true end else render :nothing => true, :status => :gone end rescue ActiveRecord::RecordNotFound render :nothing => true, :status => :not_found - rescue - render :nothing => true, :status => :internal_server_error end end diff --git a/app/models/node.rb b/app/models/node.rb index 230c83882..7e78aaf59 100644 --- a/app/models/node.rb +++ b/app/models/node.rb @@ -68,18 +68,12 @@ class Node < ActiveRecord::Base return node end - def save_with_history - begin - Node.transaction do - self.timestamp = Time.now - self.save! - old_node = OldNode.from_node(self) - old_node.save! - end - - return true - rescue - return nil + def save_with_history! + Node.transaction do + self.timestamp = Time.now + self.save! + old_node = OldNode.from_node(self) + old_node.save! end end diff --git a/app/models/segment.rb b/app/models/segment.rb index bdb807d93..6916b79b1 100644 --- a/app/models/segment.rb +++ b/app/models/segment.rb @@ -59,18 +59,12 @@ class Segment < ActiveRecord::Base return segment end - def save_with_history - begin - Segment.transaction do - self.timestamp = Time.now - self.save! - old_segment = OldSegment.from_segment(self) - old_segment.save! - end - - return true - rescue - return nil + def save_with_history! + Segment.transaction do + self.timestamp = Time.now + self.save! + old_segment = OldSegment.from_segment(self) + old_segment.save! end end -- 2.39.5