Skip to content

Commit a2847f8

Browse files
Add 404 error handling for tech report (#1122)
* Refactor imports in routes.py and add 404 error handling for tech report pages; update 404.html to simplify messaging * open gh issue in a new tab * Exclude 404 files from changed files list in lighthouse URL script * fix
1 parent f6c0158 commit a2847f8

File tree

4 files changed

+39
-10
lines changed

4 files changed

+39
-10
lines changed

server/routes.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1-
from flask import redirect, request, jsonify, abort, send_from_directory
21
import re
32

3+
from flask import abort, jsonify, redirect, request, send_from_directory
44

5-
from . import app, talisman, render_template, url_for
5+
from . import app
6+
from . import faq as faq_util
7+
from . import render_template
68
from . import reports as report_util
9+
from . import talisman
710
from . import techreport as tech_report_util
8-
from . import faq as faq_util
11+
from . import url_for
912

1013

1114
def safe_int(value, default=1):
@@ -88,6 +91,10 @@ def techreportlanding(page_id):
8891
# Get the settings for the current page
8992
active_tech_report = tech_report.get("pages").get(page_id)
9093

94+
# Check if the page exists
95+
if active_tech_report is None:
96+
abort(404)
97+
9198
# Add the technologies requested in the URL to the filters
9299
# Use the default configured techs as fallback
93100
# Use ["ALL"] if there is nothing configured

server/tests/routes_test.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,10 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
from server import app, talisman
1615
import pytest
1716

17+
from server import app, talisman
18+
1819

1920
# Create test client without https redirect
2021
# (normally taken care of by running in debug)
@@ -257,6 +258,31 @@ def test_tech_report_category_pages_fallback(client):
257258
assert response.status_code == 200
258259

259260

261+
def test_tech_report_landing_valid_page(client):
262+
response = client.get("/reports/techreport/landing")
263+
assert response.status_code == 200
264+
265+
266+
def test_tech_report_drilldown_page(client):
267+
response = client.get("/reports/techreport/drilldown")
268+
assert response.status_code == 200
269+
270+
271+
def test_tech_report_comparison_page(client):
272+
response = client.get("/reports/techreport/comparison")
273+
assert response.status_code == 200
274+
275+
276+
def test_tech_report_category_page(client):
277+
response = client.get("/reports/techreport/category")
278+
assert response.status_code == 200
279+
280+
281+
def test_tech_report_invalid_page(client):
282+
response = client.get("/reports/techreport/invalid_page_id")
283+
assert response.status_code == 404
284+
285+
260286
def test_well_known_atproto_did(client):
261287
response = client.get("/.well-known/atproto-did")
262288
assert response.status_code == 200

templates/error/404.html

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,5 @@
44
{% block error %}Page Not Found{% endblock %}
55

66
{% block custom %}
7-
<p>
8-
We've recently <a href="https://discuss.httparchive.org/t/announcing-the-new-http-archive/1294">launched a new version of the HTTP Archive</a>.
9-
Some URLs may have been updated, please take a look at our new site!
10-
If the information you're looking for is missing, please <a href="https://discuss.httparchive.org/t/announcing-the-new-http-archive/1294">let us know</a>.
11-
</p>
7+
<p>If the information you're looking for is missing, please <a href="https://github.com/HTTPArchive/httparchive.org/issues/new?template=BLANK_ISSUE" target="_blank">let us know</a>.</p>
128
{% endblock %}

tools/scripts/set_lighthouse_urls.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ elif [ "${RUN_TYPE}" == "pull_request" ] && [ "${COMMIT_SHA}" != "" ]; then
6060
git pull --quiet
6161
git checkout main
6262
# Then get the changes
63-
CHANGED_FILES=$(git diff --name-only "main...${COMMIT_SHA}" --diff-filter=d templates config/reports.json | grep -v base.html | grep -v main.html | grep -v ejs | grep -v base_ | grep -v sitemap | grep -v error.html | grep -v techreport/components | grep -v techreport/templates | grep -v techreport/report | grep -v techreport/techreport)
63+
CHANGED_FILES=$(git diff --name-only "main...${COMMIT_SHA}" --diff-filter=d templates config/reports.json | grep -v base.html | grep -v main.html | grep -v ejs | grep -v base_ | grep -v sitemap | grep -v error.html | grep -v techreport/components | grep -v techreport/templates | grep -v techreport/report | grep -v techreport/techreport | grep -v 404)
6464
echo "${CHANGED_FILES}"
6565

6666
# Then back to the pull request changes

0 commit comments

Comments
 (0)