From 1295bbea5def847cda0a79efb4ea9bef651e1bba Mon Sep 17 00:00:00 2001 From: Tobias Lins Date: Thu, 2 Jul 2020 11:48:08 +0200 Subject: [PATCH] Fix edge cases that let worker crash --- src/api/notion.ts | 23 +++++++++++++---------- src/routes/page.ts | 4 +++- src/routes/table.ts | 2 +- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/api/notion.ts b/src/api/notion.ts index f57a897..2c5303e 100644 --- a/src/api/notion.ts +++ b/src/api/notion.ts @@ -92,16 +92,19 @@ export const fetchNotionUsers = async ( }, notionToken, }); - return users.results.map((u) => { - const user = { - id: u.value.id, - firstName: u.value.given_name, - lastLame: u.value.family_name, - fullName: u.value.given_name + " " + u.value.family_name, - profilePhoto: u.value.profile_photo, - }; - return user; - }); + if (users && users.results) { + return users.results.map((u) => { + const user = { + id: u.value.id, + firstName: u.value.given_name, + lastLame: u.value.family_name, + fullName: u.value.given_name + " " + u.value.family_name, + profilePhoto: u.value.profile_photo, + }; + return user; + }); + } + return []; }; export const fetchBlocks = async ( diff --git a/src/routes/page.ts b/src/routes/page.ts index 82092f9..08d1ba7 100644 --- a/src/routes/page.ts +++ b/src/routes/page.ts @@ -22,7 +22,9 @@ export async function pageRoute(req: HandlerRequest) { const block = allBlocks[blockId]; const content = block.value.content; - return content ? content.filter((id: string) => !allBlocks[id]) : []; + return content && block.value.type !== "page" + ? content.filter((id: string) => !allBlocks[id]) + : []; }); if (!pendingBlocks.length) { diff --git a/src/routes/table.ts b/src/routes/table.ts index 3bbbeb9..692df0d 100644 --- a/src/routes/table.ts +++ b/src/routes/table.ts @@ -44,7 +44,7 @@ export const getTableData = async ( if (val) { const schema = collectionRows[key]; row[schema.name] = raw ? val : getNotionValue(val, schema.type); - if (schema.type === "person") { + if (schema.type === "person" && row[schema.name]) { const users = await fetchNotionUsers(row[schema.name] as string[]); row[schema.name] = users as any; }