Skip to content

Commit

Permalink
fix: gracefully handle no docs
Browse files Browse the repository at this point in the history
  • Loading branch information
iCrawl committed Nov 8, 2023
1 parent defeee5 commit f713e47
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 3 additions & 3 deletions apps/website/src/app/docAPI.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ export async function fetchModelJSON(packageName: string, version: string): Prom
return JSON.parse(res);
} catch {
console.log(res);
return {};
return null;
}
}

Expand All @@ -45,7 +45,7 @@ export async function fetchModelJSON(packageName: string, version: string): Prom
]);

// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0]?.data ?? {};
return rows[0]?.data ?? null;
}

const { rows } = await sql.execute('select data from documentation where name = ? and version = ?', [
Expand All @@ -54,5 +54,5 @@ export async function fetchModelJSON(packageName: string, version: string): Prom
]);

// @ts-expect-error: https://github.com/planetscale/database-js/issues/71
return rows[0]?.data ?? {};
return rows[0]?.data ?? null;
}
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,18 @@ export async function generateMetadata({ params }: { params: ItemRouteParams })

export async function generateStaticParams({ params: { package: packageName, version } }: { params: ItemRouteParams }) {
const modelJSON = await fetchModelJSON(packageName, version);

if (!modelJSON) {
return [];
}

const model = addPackageToModel(new ApiModel(), modelJSON);

const pkg = model.tryGetPackageByName(packageName);
const entry = pkg?.entryPoints[0];

if (!entry) {
notFound();
return [];
}

return entry.members.map((member: ApiItem) => ({
Expand Down

0 comments on commit f713e47

Please sign in to comment.