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

Fix grapher 404 page #3970

Merged
merged 2 commits into from
Sep 18, 2024
Merged

Fix grapher 404 page #3970

merged 2 commits into from
Sep 18, 2024

Conversation

rakyi
Copy link
Contributor

@rakyi rakyi commented Sep 17, 2024

This is an alternative fix for the one reverted in 24f6288.

@owidbot
Copy link
Contributor

owidbot commented Sep 17, 2024

Quick links (staging server):

Site Admin Wizard

Login: ssh owid@staging-site-fix-grapher-404

SVG tester:

Number of differences (default views): 0 ✅
Number of differences (all views): 0 ✅

Edited: 2024-09-17 15:06:22 UTC
Execution time: 1.19 seconds

This is an alternative fix for the one reverted in 24f6288.
Copy link
Member

@ikesau ikesau left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Tested locally with grapher routes that should 404 and grapher routes that should redirect and they all worked 👍

@@ -146,7 +102,7 @@ async function handleHtmlPageRequest(
const grapherPageResp = await env.ASSETS.fetch(url, { redirect: "manual" })

if (grapherPageResp.status === 404) {
throw new StatusError(404)
return handlePageNotFound(env, grapherPageResp)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One thing I noticed while tinkering with the code, the For local testing commented-out code block above here could be updated to call fetch from env.ASSETS

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a comment here would be useful that mentions that by passing in the grapherPageResp as the fallback we get a 404 status code but also an HTML 404 page. Otherwise this subtle detail might be lost in bigger refactorings in the future.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a comment about grapherPageResp.

commented-out code block above here could be updated to call fetch from env.ASSETS

Even if it works, I think it makes sense to leave it to a normal fetch, since we are not fetching from the assets (semantically), we are fetching from the internet.

Copy link
Contributor

@danyx23 danyx23 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I checked some of the new routes as well and it all looks good from my side too - thanks!

@@ -146,7 +102,7 @@ async function handleHtmlPageRequest(
const grapherPageResp = await env.ASSETS.fetch(url, { redirect: "manual" })

if (grapherPageResp.status === 404) {
throw new StatusError(404)
return handlePageNotFound(env, grapherPageResp)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think a comment here would be useful that mentions that by passing in the grapherPageResp as the fallback we get a 404 status code but also an HTML 404 page. Otherwise this subtle detail might be lost in bigger refactorings in the future.

@rakyi rakyi merged commit 776c003 into master Sep 18, 2024
12 of 14 checks passed
@rakyi rakyi deleted the fix-grapher-404 branch September 18, 2024 07:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants