Skip to content

Commit

Permalink
add error handling for invalid read data
Browse files Browse the repository at this point in the history
  • Loading branch information
jackiequach committed Jul 11, 2024
1 parent 71b7b43 commit 3ae14e1
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 12 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
- Fix cut off text on search bar dropdown
- Fix broken link on the About page
- SFR-2008: Automate License Page Headers and Sub-Headers
- Add error page for /read links with invalid source

## [0.18.1]

Expand Down
5 changes: 5 additions & 0 deletions src/components/ReaderLayout/ReaderLayout.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import Link from "../Link/Link";
import { addTocToManifest } from "@nypl/web-reader";
import Loading from "../Loading/Loading";
import { trackCtaClick } from "~/src/lib/adobe/Analytics";
import NotFound404 from "~/src/pages/404";

const origin =
typeof window !== "undefined" && window.location?.origin
Expand Down Expand Up @@ -68,6 +69,10 @@ const ReaderLayout: React.FC<{
const isEmbed = MediaTypes.embed.includes(link.media_type);
const isRead = MediaTypes.read.includes(link.media_type);

if (!isEmbed && !isRead) {
return NotFound404();
}

const pdfWorkerSrc = `${origin}/pdf-worker/pdf.worker.min.js`;

/**
Expand Down
34 changes: 22 additions & 12 deletions src/pages/404.tsx
Original file line number Diff line number Diff line change
@@ -1,21 +1,31 @@
import { TemplateAppContainer } from "@nypl/design-system-react-components";
import React from "react";
import DrbBreakout from "../components/DrbBreakout/DrbBreakout";
import Layout from "../components/Layout/Layout";
import Link from "../components/Link/Link";

const NotFound404 = () => (
<Layout>
<h1>404 Not Found</h1>
const NotFound404 = () => {
const contentPrimaryElement = (
<>
<h1>404 Not Found</h1>

<p>We&apos;re sorry...</p>
<p>We&apos;re sorry...</p>

<p>The page you were looking for doesn&apos;t exist.</p>
<p>The page you were looking for doesn&apos;t exist.</p>

<p>
Search&nbsp;
<Link to="/">Digital Research Books Beta</Link>
{"."}
</p>
</Layout>
);
<p>
Search&nbsp;
<Link to="/">Digital Research Books Beta</Link>
{"."}
</p>
</>
);

return (
<Layout>
<TemplateAppContainer breakout={<DrbBreakout />} contentPrimary={contentPrimaryElement} />
</Layout>
);
};

export default NotFound404;

0 comments on commit 3ae14e1

Please sign in to comment.