diff --git a/app/controllers/posts_controller.rb b/app/controllers/posts_controller.rb index 9c1e4c073..2013b6746 100644 --- a/app/controllers/posts_controller.rb +++ b/app/controllers/posts_controller.rb @@ -2,6 +2,7 @@ class PostsController < ApplicationController before_filter :member_only, :except => [:show, :index] after_filter :save_recent_tags, :only => [:update] respond_to :html, :xml, :json + rescue_from PostSets::SearchError, :with => :search_error def index @post_set = PostSets::Post.new(tag_query, params[:page]) @@ -38,6 +39,11 @@ class PostsController < ApplicationController end private + def search_error(exception) + @exception = exception + render :action => "error" + end + def tag_query params[:tags] || (params[:post] && params[:post][:tags]) end diff --git a/app/logical/post_sets/post.rb b/app/logical/post_sets/post.rb index e1062ae4b..6e8b3c21a 100644 --- a/app/logical/post_sets/post.rb +++ b/app/logical/post_sets/post.rb @@ -1,7 +1,4 @@ module PostSets - class SearchError < Exception - end - class Post < Base attr_reader :tag_array, :page @@ -28,7 +25,7 @@ module PostSets def posts if tag_array.size > 2 && !CurrentUser.is_privileged? - raise SearchError + raise SearchError.new("Upgrade your account to search more than two tags at once") end @posts ||= ::Post.tag_match(tag_string).paginate(page) diff --git a/app/logical/post_sets/search_error.rb b/app/logical/post_sets/search_error.rb new file mode 100644 index 000000000..8899c1e86 --- /dev/null +++ b/app/logical/post_sets/search_error.rb @@ -0,0 +1,4 @@ +module PostSets + class SearchError < Exception + end +end \ No newline at end of file diff --git a/app/views/posts/error.html.erb b/app/views/posts/error.html.erb new file mode 100644 index 000000000..03a41e20c --- /dev/null +++ b/app/views/posts/error.html.erb @@ -0,0 +1 @@ +

Error: <%= @exception.to_s %>

\ No newline at end of file diff --git a/app/views/posts/error.json.erb b/app/views/posts/error.json.erb new file mode 100644 index 000000000..b913112fc --- /dev/null +++ b/app/views/posts/error.json.erb @@ -0,0 +1 @@ +{success: false, message: "<%= @exception.to_s %>"} \ No newline at end of file diff --git a/app/views/posts/error.xml.erb b/app/views/posts/error.xml.erb new file mode 100644 index 000000000..9808698dd --- /dev/null +++ b/app/views/posts/error.xml.erb @@ -0,0 +1,2 @@ + +<%= @exception.to_s %>