Skip to content

Commit c904901

Browse files
committed
catching null page IDs
1 parent 3173af9 commit c904901

File tree

1 file changed

+11
-0
lines changed

1 file changed

+11
-0
lines changed

src/routes/page.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,24 @@ export async function pageRoute(req: HandlerRequest) {
88
const pageId = parsePageId(req.params.pageId);
99
const page = await fetchPageById(pageId!, req.notionToken);
1010

11+
if (!pageId || !page.recordMap)
12+
console.error(`Page not found at [ID:${req.params.pageId}]`)
13+
return createResponse(
14+
JSON.stringify({ error: "No page found on Notion at: " + pageId }),
15+
{},
16+
401
17+
);
18+
19+
1120
const baseBlocks = page.recordMap.block;
1221

1322
let allBlocks: { [id: string]: BlockType & { collection?: any } } = {
1423
...baseBlocks,
1524
};
1625
let allBlockKeys;
1726

27+
28+
1829
while (true) {
1930
allBlockKeys = Object.keys(allBlocks);
2031

0 commit comments

Comments
 (0)