Skip to content

Commit

Permalink
Revert "Log auth document URL when Catalog Root link missing. (PP-1209)"
Browse files Browse the repository at this point in the history
This reverts commit 18788be.
  • Loading branch information
tdilauro committed Jan 28, 2025
1 parent 18788be commit a370ff3
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 62 deletions.
28 changes: 0 additions & 28 deletions src/dataflow/__tests__/getLibraryData.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -111,34 +111,6 @@ describe("buildLibraryData", () => {
});
});

test("throws ApplicationError with auth doc URL, if auth doc has no catalog root url", () => {
// Make sure that the error is actually thrown.
expect.assertions(2);

try {
buildLibraryData(fixtures.authDocNoCatalogRoot, "librarySlug");
} catch (error) {
expect(error).toBeInstanceOf(ApplicationError);
expect(error.message).toBe(
"Application Error: No Catalog Root URL present in Auth Document at /auth-doc."
);
}
});

test("throws ApplicationError without auth doc URL, if auth doc has no self url", () => {
// Make sure that the error is actually thrown.
expect.assertions(2);

try {
buildLibraryData(fixtures.authDocNoLinks, "librarySlug");
} catch (error) {
expect(error).toBeInstanceOf(ApplicationError);
expect(error.message).toBe(
"Application Error: No Catalog Root URL present in Auth Document at (unknown: missing auth doc 'self' link or href)."
);
}
});

test("correctly parses web_color_scheme", () => {
const library = buildLibraryData(
{
Expand Down
16 changes: 7 additions & 9 deletions src/dataflow/getLibraryData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import { LibraryData, LibraryLinks, OPDS1 } from "interfaces";
import ApplicationError, { PageNotFoundError, ServerError } from "errors";
import { flattenSamlMethod } from "utils/auth";
import { APP_CONFIG } from "utils/env";
import { AuthDocumentLink } from "../types/opds1";

/**
* Interprets the app config to return the auth document url.
Expand Down Expand Up @@ -48,19 +47,18 @@ function getShelfUrl(authDoc: OPDS1.AuthDocument): string | null {
}

/**
* Extracts the catalog root url from an auth document
* Extracts the catalot root url from an auth document
*/
function getCatalogUrl(authDoc: OPDS1.AuthDocument): string {
const url: string | undefined =
authDoc.links?.find(link => link.rel === OPDS1.CatalogRootRel)?.href ?? null;
const url =
authDoc.links?.find(link => {
return link.rel === OPDS1.CatalogRootRel;
})?.href ?? null;

if (!url) {
const selfUrl =
authDoc.links?.find(link => link.rel === OPDS1.SelfRel)?.href ?? "(unknown: missing auth doc 'self' link or href)";
if (!url)
throw new ApplicationError({
detail: `No Catalog Root URL present in Auth Document at ${selfUrl}.`
detail: "No Catalog Root Url present in Auth Document."
});
}

return url;
}
Expand Down
27 changes: 2 additions & 25 deletions src/test-utils/fixtures/auth-document.ts
Original file line number Diff line number Diff line change
@@ -1,37 +1,14 @@
import { OPDS1 } from "interfaces";

const baseAuthDoc: OPDS1.AuthDocument = {
export const authDoc: OPDS1.AuthDocument = {
id: "auth-doc-id",
title: "auth doc title",
description: "auth doc description",
links: [],
authentication: [],
};

export const authDoc: OPDS1.AuthDocument = {
...baseAuthDoc,
links: [
...baseAuthDoc.links,
{
rel: OPDS1.SelfRel,
href: "/auth-doc"
},
{
rel: OPDS1.CatalogRootRel,
href: "/catalog-root"
}
],
};

export const authDocNoLinks: OPDS1.AuthDocument = { ...baseAuthDoc };

export const authDocNoCatalogRoot: OPDS1.AuthDocument = {
...baseAuthDoc,
links: [
...baseAuthDoc.links,
{
rel: OPDS1.SelfRel,
href: "/auth-doc"
}
]
authentication: []
};

0 comments on commit a370ff3

Please sign in to comment.