diff --git a/src/lib/api/addons.ts b/src/lib/api/addons.ts index a46e65894..07a3f4cd2 100644 --- a/src/lib/api/addons.ts +++ b/src/lib/api/addons.ts @@ -19,7 +19,7 @@ export async function getAddons( params: AddOnParams = {}, fetch = globalThis.fetch, ): Promise> { - const endpoint = new URL("addons", BASE_API_URL); + const endpoint = new URL("addons/", BASE_API_URL); Object.entries(params).forEach(([key, value]) => { endpoint.searchParams.set(key, String(value)); }); diff --git a/src/lib/api/documents.ts b/src/lib/api/documents.ts index ec6899151..662c0fa99 100644 --- a/src/lib/api/documents.ts +++ b/src/lib/api/documents.ts @@ -60,10 +60,24 @@ export async function get( fetch: typeof globalThis.fetch = globalThis.fetch, ): Promise { const endpoint = new URL(`documents/${id}.json`, BASE_API_URL); - const expand = ["user", "organization", "projects", "revisions", "sections"]; + const expand = [ + "user", + "organization", + "projects", + "revisions", + "sections", + "notes", + ]; endpoint.searchParams.set("expand", expand.join(",")); - const resp = await fetch(endpoint, { credentials: "include" }); + const resp = await fetch(endpoint, { credentials: "include" }).catch( + console.error, + ); + + // backend error, not much we can do + if (!resp) { + error(500); + } if (isErrorCode(resp.status)) { error(resp.status, resp.statusText); diff --git a/src/routes/documents/[id]-[slug]/+layout.ts b/src/routes/documents/[id]-[slug]/+layout.ts index ab90aede8..1df17523c 100644 --- a/src/routes/documents/[id]-[slug]/+layout.ts +++ b/src/routes/documents/[id]-[slug]/+layout.ts @@ -3,10 +3,10 @@ * We do this in a layout module because sub-routes can use the same * document without loading it again. */ - -import { redirect } from "@sveltejs/kit"; -import * as documents from "@/lib/api/documents"; import type { Document } from "@/lib/api/types"; + +import { redirect, error } from "@sveltejs/kit"; +import * as documents from "$lib/api/documents"; import { getPinnedAddons } from "$lib/api/addons"; import { breadcrumbTrail } from "$lib/utils/navigation"; @@ -16,7 +16,12 @@ function documentPath(document: Document) { /** @type {import('./$types').PageLoad} */ export async function load({ fetch, params, parent }) { - const document = await documents.get(+params.id, fetch); + const document = await documents.get(+params.id, fetch).catch(console.error); + + console.log({ document }); + if (!document) { + error(404, "Document not found"); + } if (document.slug !== params.slug) { const canonical = new URL(document.canonical_url); diff --git a/src/routes/documents/[id]-[slug]/+page.ts b/src/routes/documents/[id]-[slug]/+page.ts deleted file mode 100644 index 5d274b196..000000000 --- a/src/routes/documents/[id]-[slug]/+page.ts +++ /dev/null @@ -1,10 +0,0 @@ -/** Load notes and sections for viewing a single document */ -import * as notes from "$lib/api/notes"; - -/** @type {import('./$types').PageLoad} */ -export async function load({ params, fetch }) { - // stream these, because we can wait on them - return { - notes: notes.list(+params.id, fetch), - }; -}