Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AO3-6911 Add error page for Rack::Timeout::RequestTimeoutException #5074

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions app/controllers/application_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ def raise_not_found
redirect_to '/404'
end

rescue_from Rack::Timeout::RequestTimeoutException, with: :raise_timeout

def raise_timeout
redirect_to timeout_error_path
end

helper :all # include all helpers, all the time

include HtmlCleaner
Expand Down
7 changes: 6 additions & 1 deletion app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
end

def auth_error
@page_subtitle = "Auth Error"
@page_subtitle = t(".subtitle")
end

def timeout_error
@page_subtitle = t(".subtitle")
render "timeout_error", status: 504, formats: :html

Check warning on line 14 in app/controllers/errors_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer `:gateway_timeout` over `504` to define HTTP status code. Raw Output: app/controllers/errors_controller.rb:14:37: C: Rails/HttpStatus: Prefer `:gateway_timeout` over `504` to define HTTP status code.
end
end
3 changes: 3 additions & 0 deletions app/views/errors/timeout_error.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<h2 class="heading"><%= t(".title") %></h2>
<h3 class="heading"><%= t(".subtitle") %></h3>
<p><%= t(".html", contact_support_link: link_to(t(".contact_support_link"), new_feedback_report_path)) %></p>

Check failure on line 3 in app/views/errors/timeout_error.html.erb

View workflow job for this annotation

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 Missing a trailing newline at the end of the file. Raw Output: app/views/errors/timeout_error.html.erb:3:109: Missing a trailing newline at the end of the file.
5 changes: 5 additions & 0 deletions config/locales/controllers/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,11 @@ en:
error: Sorry, that comment could not be unhidden.
permission_denied: Sorry, you don't have permission to unhide that comment.
success: Comment successfully unhidden!
errors:
timeout_error:
subtitle: "Timeout Error"
auth_error:
subtitle: "Authentication Error"
external_works:
update:
successfully_updated: External work was successfully updated.
Expand Down
6 changes: 6 additions & 0 deletions config/locales/views/en.yml
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,12 @@ en:
restricted_html: A translation of [Restricted Work] by %{creator_link}
revealed_html: A translation of %{work_link} by %{creator_link}
unrevealed: A translation of a work in an unrevealed collection
errors:
timeout_error:
title: Timeout
subtitle: The page was responding too slowly. Please try again after a few minutes.
html: If you still get this error after a few tries, please %{contact_support_link}.
contact_support_link: contact Support
feedbacks:
new:
abuse:
Expand Down
1 change: 1 addition & 0 deletions config/routes.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@
get '/422', to: 'errors#422'
get '/500', to: 'errors#500'
get '/auth_error', to: 'errors#auth_error'
get "/timeout_error", to: "errors#timeout_error"

#### DOWNLOADS ####

Expand Down
16 changes: 16 additions & 0 deletions spec/controllers/errors_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,20 @@
expect(response.header["Content-Type"]).to eq("text/html; charset=utf-8")
end
end

describe "GET #auth_error" do
it "returns an HTML auth error page" do
get :auth_error
expect(response.status).to eq(200)
expect(response.header["Content-Type"]).to eq("text/html; charset=utf-8")
end
end

describe "GET #timeout_error" do
it "returns an HTML timeout error page" do
get :timeout_error
expect(response.status).to eq(504)
expect(response.header["Content-Type"]).to eq("text/html; charset=utf-8")
end
end
end
Loading