diff --git a/app/controllers/errors_controller.rb b/app/controllers/errors_controller.rb deleted file mode 100644 index 65781559f..000000000 --- a/app/controllers/errors_controller.rb +++ /dev/null @@ -1,27 +0,0 @@ -class ErrorsController < ApplicationController - GITHUB_BUG_REPORT_DOMAINS = ["dev.to", "forem.dev"].freeze - GITHUB_BUG_REPORT_URL = "https://github.com/forem/forem/issues/new?template=bug_report.md".freeze - - # HTTP 404 - Not Found - https://httpstatuses.com/400 - def not_found - render status: :not_found - end - - # HTTP 422 - Unprocessable Entity - https://httpstatuses.com/422 - def unprocessable_entity - render status: :unprocessable_entity - end - - # HTTP 500 - Internal Server Error - https://httpstatuses.com/500 - def internal_server_error - @github_bug_report_url = GITHUB_BUG_REPORT_URL - @display_github_bug_report_url = SiteConfig.app_domain.in?(GITHUB_BUG_REPORT_DOMAINS) - - render status: :internal_server_error - end - - # HTTP 503 - Service Unavailable - https://httpstatuses.com/503 - def service_unavailable - render status: :service_unavailable - end -end diff --git a/app/models/comment.rb b/app/models/comment.rb index 801e445f9..1662d0a7b 100644 --- a/app/models/comment.rb +++ b/app/models/comment.rb @@ -75,7 +75,7 @@ class Comment < ApplicationRecord def path "/#{user.username}/comment/#{id_code_generated}" rescue StandardError - "/404" + "/404.html" end def parent_or_root_article diff --git a/app/views/errors/internal_server_error.html.erb b/app/views/errors/internal_server_error.html.erb deleted file mode 100644 index 8fc95f755..000000000 --- a/app/views/errors/internal_server_error.html.erb +++ /dev/null @@ -1,87 +0,0 @@ - - - - We're sorry, but something went wrong (500) - - - - - - -
-
-
- 500 error -

Ooooops...

-

You have encountered an error.

-
- -

- Our team has been notified. - - <% if @display_github_bug_report_url %> - Please feel welcome to also submit a public - bug report. - <% end %> - -

- We apologize for any inconvenience. -

-
-
- - diff --git a/app/views/service_worker/index.js.erb b/app/views/service_worker/index.js.erb index 17c552140..45dad8045 100644 --- a/app/views/service_worker/index.js.erb +++ b/app/views/service_worker/index.js.erb @@ -1,6 +1,6 @@ // Serviceworkers file. This code gets installed in users browsers and runs code before the request is made. <% unless Rails.env.test? || ENV["SKIP_SERVICEWORKERS"] == "true" %> - const staticCacheName = 'static-1.3'; + const staticCacheName = 'static-1.4'; const expectedCaches = [ staticCacheName ]; @@ -15,12 +15,12 @@ event.waitUntil( caches.open(staticCacheName) .then(cache => cache.addAll([ - "/shell_top", // head, top bar, inline styles - "/shell_bottom", // footer - "/async_info/shell_version", // For comparing changes in the shell. Should be incremented with style changes. - "/not_found.html", // 404 etc. - "/error.html", // 500 etc. - "/offline.html" // Offline page + "/shell_top", // head, top bar, inline styles + "/shell_bottom", // footer + "/async_info/shell_version", // For comparing changes in the shell. Should be incremented with style changes. + "/404.html", // Not found page + "/500.html", // Error page + "/offline.html" //Offline page ])) ); }); @@ -54,10 +54,10 @@ const endFetch = Promise.resolve(cachedShellBottom); const middleFetch = fetch(url).then(response => { if (!response.ok && response.status === 404) { - return caches.match('/not_found.html'); + return caches.match('/404.html'); } if (!response.ok && response.status != 404) { - return caches.match('/error.html'); + return caches.match('/500.html'); } return response; }).catch(err => caches.match('/offline.html')); diff --git a/config/application.rb b/config/application.rb index 1383d239a..d1fbae8fe 100644 --- a/config/application.rb +++ b/config/application.rb @@ -67,10 +67,6 @@ module PracticalDeveloper # To improve security, Rails embeds the purpose and expiry metadata inside encrypted or signed cookies value. config.action_dispatch.use_cookies_with_metadata = false - # Sets the exceptions application invoked by the ShowException middleware when an exception happens - # Defaults to ActionDispatch::PublicExceptions.new(Rails.public_path) - config.exceptions_app = routes # use ErrorsController to handle error pages - # After-initialize checker to add routes to reserved words config.after_initialize do # Add routes to reserved words diff --git a/config/routes.rb b/config/routes.rb index d327d4f9c..1eb6b9a6a 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -1,12 +1,6 @@ # rubocop:disable Metrics/BlockLength Rails.application.routes.draw do - # errors routes - match "/404", to: "errors#not_found", via: :all, as: :errors_not_found - match "/422", to: "errors#unprocessable_entity", via: :all, as: :errors_unprocessable_entity - match "/500", to: "errors#internal_server_error", via: :all, as: :errors_internal_server_error - match "/503", to: "errors#service_unavailable", via: :all, as: :errors_service_unavailable - use_doorkeeper do controllers tokens: "oauth/tokens" end diff --git a/app/views/errors/not_found.html.erb b/public/404.html similarity index 100% rename from app/views/errors/not_found.html.erb rename to public/404.html diff --git a/app/views/errors/unprocessable_entity.html.erb b/public/422.html similarity index 97% rename from app/views/errors/unprocessable_entity.html.erb rename to public/422.html index 8c5e0802b..a21f82b3b 100644 --- a/app/views/errors/unprocessable_entity.html.erb +++ b/public/422.html @@ -55,6 +55,7 @@ +

The change you wanted was rejected.

diff --git a/public/error.html b/public/500.html similarity index 96% rename from public/error.html rename to public/500.html index 2b8924854..98e2b514c 100644 --- a/public/error.html +++ b/public/500.html @@ -62,6 +62,7 @@ +
@@ -72,7 +73,7 @@

Our team has been notified. -

+

We apologize for any inconvenience.

diff --git a/app/views/errors/service_unavailable.html.erb b/public/503.html similarity index 100% rename from app/views/errors/service_unavailable.html.erb rename to public/503.html diff --git a/public/not_found.html b/public/not_found.html deleted file mode 100644 index 7978c4e90..000000000 --- a/public/not_found.html +++ /dev/null @@ -1,101 +0,0 @@ - - - - The page you were looking for doesn't exist (404) - - - - - -
-
-
- 404 not found -
-

This page does not exist

Return to Home Page

-
-
-
- - diff --git a/spec/requests/errors_request_spec.rb b/spec/requests/errors_request_spec.rb deleted file mode 100644 index 7cb5ac107..000000000 --- a/spec/requests/errors_request_spec.rb +++ /dev/null @@ -1,53 +0,0 @@ -require "rails_helper" - -RSpec.describe "Errors", type: :request do - describe "GET /404" do - it "returns not found error" do - get errors_not_found_path - - expect(response).to have_http_status(:not_found) - end - end - - describe "GET /422" do - it "returns unprocessable entity error" do - get errors_unprocessable_entity_path - - expect(response).to have_http_status(:unprocessable_entity) - end - end - - describe "GET /500" do - it "returns internal server error" do - get errors_internal_server_error_path - - expect(response).to have_http_status(:internal_server_error) - end - - it "does not include the prompt to report on Forem GitHub" do - allow(SiteConfig).to receive(:app_domain).and_return("example.com") - - get errors_internal_server_error_path - - expect(response).to have_http_status(:internal_server_error) - expect(response.body).not_to include("github.com/forem/forem/issues") - end - - it "includes the prompt to report on Forem GitHub for DEV" do - allow(SiteConfig).to receive(:app_domain).and_return("dev.to") - - get errors_internal_server_error_path - - expect(response).to have_http_status(:internal_server_error) - expect(response.body).to include("github.com/forem/forem/issues") - end - end - - describe "GET /503" do - it "returns service unavailable error" do - get errors_service_unavailable_path - - expect(response).to have_http_status(:service_unavailable) - end - end -end