Skip to content

Commit

Permalink
AO3-6911: add timeout page as catch to Rack::Timeout::RequestTimeoutE…
Browse files Browse the repository at this point in the history
…xception
  • Loading branch information
boyer-victor committed Feb 20, 2025
1 parent 775ed13 commit c420089
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 0 deletions.
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'

Check warning on line 31 in app/controllers/application_controller.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: app/controllers/application_controller.rb:31:17: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
end

helper :all # include all helpers, all the time

include HtmlCleaner
Expand Down
4 changes: 4 additions & 0 deletions app/controllers/errors_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,8 @@ class ErrorsController < ApplicationController
def auth_error
@page_subtitle = "Auth Error"
end

def timeout_error
@page_subtitle = "Timeout Error"
end
end
2 changes: 2 additions & 0 deletions app/views/errors/timeout.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<h3 class="heading">The page was responding too slowly. Please try again after a few minutes.</h3>
<p>If you still get this error after a few tries, you can <%= link_to ts('contact Support'), new_feedback_report_path %>. In the form, please include a link to the page you're trying to reach and what action you are taking.</p>

Check failure on line 2 in app/views/errors/timeout.html.erb

View workflow job for this annotation

GitHub Actions / ERB Lint runner

[] reported by reviewdog 🐶 Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: app/views/errors/timeout.html.erb:2:74: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
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', to: 'errors#timeout'

Check warning on line 56 in config/routes.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: config/routes.rb:56:7: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

Check warning on line 56 in config/routes.rb

View workflow job for this annotation

GitHub Actions / Rubocop

[rubocop] reported by reviewdog 🐶 Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping. Raw Output: config/routes.rb:56:23: C: Style/StringLiterals: Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.

#### 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 "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 "timeout" do
it "returns an HTML timeout error page" do
get :timeout
expect(response.status).to eq(200)
expect(response.header["Content-Type"]).to eq("text/html; charset=utf-8")
end
end
end

0 comments on commit c420089

Please sign in to comment.