Restore static error pages (#11882)

* Revert "Use static error files in serviceworker (#11806)"

This reverts commit 2c96c14021.

* Revert "Use custom, dynamic, error pages (#11744)"

This reverts commit 2ab0719501.

* Remove GitHub report prompt for good, see #11718

* Bump service worker cache version
This commit is contained in:
rhymes 2020-12-14 18:06:41 +01:00 committed by GitHub
parent d24a40944c
commit d8bc399a56
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 13 additions and 289 deletions

View file

@ -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

View file

@ -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

View file

@ -1,87 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>We're sorry, but something went wrong (500)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
body {
font-family: "Helvetica Neue", Helvetica, Arial, "Lucida Grande", sans-serif;
}
.unhandled-error-page {
height: 100vh;
min-height: 550px;
padding-top: 10vh;
}
.dialog{
background:rgb(236, 236, 236);
border:2px solid rgb(217, 217, 217);
text-align:center;
padding:30px 0px;
margin:5% auto;
width:80%;
max-width:580px;
min-width:315px;
color:rgb(44, 46, 50);
border-radius:8px;
min-height: 500px;
}
textarea{
width:75%;
height:100px;
border:1px solid rgb(182, 182, 182);
border-radius:3px;
padding:8px;
font-size:14px;
}
.actions{
text-align: center;
}
.g-recaptcha{
display: inline-block;
text-align: center;
margin: 15px;
}
input[type="submit"]{
width:150px;
padding:10px;
background:rgb(12, 181, 140);
color:white;
border:0px;
border-radius:3px;
font-size:15px;
margin-top:5px;
cursor:pointer;
}
img{
max-width:100%;
height:200px;
border-radius: 5px;
}
</style>
<script src='https://www.google.com/recaptcha/api.js'></script>
</head>
<body>
<div class="unhandled-error-page base-background-color">
<div class="dialog">
<div>
<img alt="500 error" src="https://media.giphy.com/media/SX9TFmjF0eChq/200.gif" height="200" />
<h1>Ooooops...</h1>
<h2>You have encountered an error.</h2>
</div>
<p style="margin: 10%">
Our team has been notified.
<% if @display_github_bug_report_url %>
Please feel welcome to also submit a public
<a href="<%= @github_bug_report_url %>" target="_blank" rel="noopener noreferer">bug report</a>.
<% end %>
<br><br />
We apologize for any inconvenience.
</p>
</div>
</div>
</body>
</html>

View file

@ -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'));

View file

@ -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

View file

@ -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

View file

@ -55,6 +55,7 @@
</head>
<body>
<!-- This file lives in public/422.html -->
<div class="dialog">
<div>
<h1>The change you wanted was rejected.</h1>

View file

@ -62,6 +62,7 @@
</head>
<body>
<!-- This file lives in public/500.html -->
<div class="unhandled-error-page base-background-color">
<div class="dialog">
<div>
@ -72,7 +73,7 @@
<p style="margin: 10%">
Our team has been notified.
<br><br />
<br><br/>
We apologize for any inconvenience.
</p>
</div>

View file

@ -1,101 +0,0 @@
<!DOCTYPE html>
<html>
<head>
<title>The page you were looking for doesn't exist (404)</title>
<meta name="viewport" content="width=device-width,initial-scale=1">
<style>
.not-found-page {
height: 100vh;
min-height: 500px;
}
.tv__outer {
display: table;
position: absolute;
height: 98%;
width: 98%;
}
.tv__middle {
display: table-cell;
vertical-align: middle;
position: relative;
}
.tv__inner {
margin-left: auto;
margin-right: auto;
display: table;
}
.tv__inner--special {
position: absolute;
left: 0;
right: 0;
margin: auto;
-webkit-animation-name: fade;
-webkit-animation-iteration-count: infinite;
-webkit-animation-duration: 2s;
animation-name: fade;
animation-iteration-count: infinite;
animation-duration: 2s;
}
.tv__inner--text {
margin-left: auto;
margin-right: auto;
display: table;
font-size: 22px;
font-weight: 500;
}
.tv__inner--special, .tv__inner {
max-width: 85%;
width: 300px;
border: 25px solid rgb(54, 55, 124);
border-radius: 36px;
}
.tv__inner--text {
text-align: center;
max-width: 90%;
}
@-webkit-keyframes fade {
0% {opacity: 1;}
10% {opacity: 1;}
20% {opacity: 0;}
25% {opacity: 0;}
28% {opacity: 0;}
30% {opacity: 0;}
33% {opacity: 1;}
45% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
@keyframes fade {
0% {opacity: 1;}
10% {opacity: 1;}
20% {opacity: 0;}
25% {opacity: 0;}
28% {opacity: 0;}
30% {opacity: 0;}
33% {opacity: 1;}
45% {opacity: 1;}
53% {opacity: 0;}
100% {opacity: 0;}
}
</style>
</head>
<body>
<div class="not-found-page base-background-color">
<div class="tv__outer">
<div class="tv__middle">
<img class="tv__inner" src="https://i.imgur.com/AdvTDlI.jpg" alt="404 not found">
<br>
<p class="tv__inner--text">This page does not exist <br><br> <a href="/">Return to Home Page</a></p>
</div>
</div>
</div>
</body>
</html>

View file

@ -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