Add error pages for tag limit and pagination errors.
This commit is contained in:
@@ -62,9 +62,9 @@ class ApplicationController < ActionController::Base
|
|||||||
when ActionController::UnknownFormat, ActionView::MissingTemplate
|
when ActionController::UnknownFormat, ActionView::MissingTemplate
|
||||||
render_error_page(406, exception, message: "#{request.format.to_s} is not a supported format for this page")
|
render_error_page(406, exception, message: "#{request.format.to_s} is not a supported format for this page")
|
||||||
when Danbooru::Paginator::PaginationError
|
when Danbooru::Paginator::PaginationError
|
||||||
render_error_page(410, exception)
|
render_error_page(410, exception, template: "static/pagination_error", message: "You cannot go beyond page #{Danbooru.config.max_numbered_pages}.")
|
||||||
when Post::SearchError
|
when Post::SearchError
|
||||||
render_error_page(422, exception)
|
render_error_page(422, exception, template: "static/tag_limit_error", message: "You cannot search for more than #{CurrentUser.tag_query_limit} tags at a time.")
|
||||||
when ApiLimitError
|
when ApiLimitError
|
||||||
render_error_page(429, exception)
|
render_error_page(429, exception)
|
||||||
when NotImplementedError
|
when NotImplementedError
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ module Danbooru
|
|||||||
page = [page.to_i, 1].max
|
page = [page.to_i, 1].max
|
||||||
|
|
||||||
if page > Danbooru.config.max_numbered_pages
|
if page > Danbooru.config.max_numbered_pages
|
||||||
raise ::Danbooru::Paginator::PaginationError.new("You cannot go beyond page #{Danbooru.config.max_numbered_pages}. Please narrow your search terms.")
|
raise ::Danbooru::Paginator::PaginationError
|
||||||
end
|
end
|
||||||
|
|
||||||
extending(NumberedCollectionExtension).limit(records_per_page).offset((page - 1) * records_per_page).tap do |obj|
|
extending(NumberedCollectionExtension).limit(records_per_page).offset((page - 1) * records_per_page).tap do |obj|
|
||||||
|
|||||||
@@ -122,7 +122,7 @@ class PostQueryBuilder
|
|||||||
relation = read_only ? PostReadOnly.all : Post.all
|
relation = read_only ? PostReadOnly.all : Post.all
|
||||||
|
|
||||||
if q[:tag_count].to_i > Danbooru.config.tag_query_limit
|
if q[:tag_count].to_i > Danbooru.config.tag_query_limit
|
||||||
raise ::Post::SearchError.new("You cannot search for more than #{Danbooru.config.tag_query_limit} tags at a time")
|
raise ::Post::SearchError
|
||||||
end
|
end
|
||||||
|
|
||||||
if CurrentUser.safe_mode?
|
if CurrentUser.safe_mode?
|
||||||
|
|||||||
17
app/views/static/pagination_error.html.erb
Normal file
17
app/views/static/pagination_error.html.erb
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
<h1>Search Error</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= @message %>
|
||||||
|
|
||||||
|
<% if CurrentUser.is_platinum? %>
|
||||||
|
Try narrowing your search terms.
|
||||||
|
<% else %>
|
||||||
|
Try narrowing your search terms, or <%= link_to "upgrade your account", new_user_upgrade_path %> to go beyond page <%= Danbooru.config.max_numbered_pages %>.
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<%= link_to "Go back", :back, rel: "prev" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Search Error - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
15
app/views/static/tag_limit_error.html.erb
Normal file
15
app/views/static/tag_limit_error.html.erb
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
<h1>Search Error</h1>
|
||||||
|
|
||||||
|
<p>
|
||||||
|
<%= @message %>
|
||||||
|
|
||||||
|
<% unless CurrentUser.is_platinum? %>
|
||||||
|
<%= link_to "Upgrade your account", new_user_upgrade_path %> to search for more tags at once.
|
||||||
|
<% end %>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
<%= link_to "Go back", :back, rel: "prev" %>
|
||||||
|
|
||||||
|
<% content_for(:page_title) do %>
|
||||||
|
Search Error - <%= Danbooru.config.app_name %>
|
||||||
|
<% end %>
|
||||||
@@ -66,6 +66,20 @@ class PostsControllerTest < ActionDispatch::IntegrationTest
|
|||||||
get posts_path, params: {:tags => "1girl solo"}
|
get posts_path, params: {:tags => "1girl solo"}
|
||||||
assert_response :success
|
assert_response :success
|
||||||
end
|
end
|
||||||
|
|
||||||
|
should "render an error when searching for too many tags" do
|
||||||
|
get posts_path, params: { tags: "1 2 3" }
|
||||||
|
|
||||||
|
assert_response 422
|
||||||
|
assert_select "h1", "Search Error"
|
||||||
|
end
|
||||||
|
|
||||||
|
should "render an error when exceeding the page limit" do
|
||||||
|
get posts_path, params: { page: 1001 }
|
||||||
|
|
||||||
|
assert_response 410
|
||||||
|
assert_select "h1", "Search Error"
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "with an md5 param" do
|
context "with an md5 param" do
|
||||||
|
|||||||
Reference in New Issue
Block a user