Return friendly page for missing embed slugs#600
Return friendly page for missing embed slugs#600skaphan wants to merge 4 commits intoartoonie:mainfrom
Conversation
When an embedded visualization URL references a slug that no longer exists, return a user-friendly HTML page (200) instead of Django default 404. This displays cleanly inside iframes and avoids cross-origin error handling issues. Cache headers prevent the response from being cached so the real visualization appears once re-created. Co-Authored-By: Claude Opus 4.6
|
Should we still return an error code 404, even with a custom 404 page? Would that display cleanly in iframes? I fear returning a 200 OK for a nonexistent page. |
|
Hi Armin,
Browsers deliberately block cross-origin error detection in iframes — the embedding page can't
tell whether an iframe loaded successfully or got a 404. There's no onerror event, no way to read
the response status, and even postMessage requires cooperation from the loaded page (which
doesn't exist if it's a 404). So the only way to show the user a helpful message is to return it
from the server as a normal 200 response.
That said, I'm fine if you don't want this change, but for my local instance I will probably keep it
since I don't have a persistent database and if rcvis instances come and go, I don't want users to
see a sad face in the middle of the iframe with no explanation, which is the alternative.
Just let me know either way, please.
Shel
… On Mar 4, 2026, at 1:09 PM, Armin Samii ***@***.***> wrote:
Should we still return an error code 404, even with a custom 404 page? Would that display cleanly in iframes? I fear returning a 200 OK for a nonexistent page.
|
|
I'm not sure I fully understand why returning the same content with 200 vs 404 acts any differently in an iframe. My understanding is that it will work the same way. The only differences are in how Cloudflare and crawlers treat the page. (If I return 200, that page might show up in search engines if there are broken links from other websites, for example.) Can you test the small change I made and see if this does everything you need it to? |
|
Tested — the friendly HTML renders correctly in iframes with 404 status. You're right that the status code doesn't affect iframe rendering. Good call on using 404 for Cloudflare and crawlers. LGTM, please merge. |
Co-Authored-By: Claude Opus 4.6
|
Running Heroku CI on #606 |
|
Looks like it's failing two tests: and |
The view now correctly returns 404 with friendly HTML content. Update the test to match. Co-Authored-By: Claude Opus 4.6
|
Fixed the second error which was triggered by the change to returning 404 status. The first one (electionpage) appears to be unrelated. Not sure what is causing it. |
Summary
/ve/<slug>) references a slug that no longer exists, return a user-friendly HTML page (200) instead of Django's default 404Test plan
test_embedded_404_returns_friendly_pagetotestSimple.py🤖 Generated with Claude Code