Fix edge cases that let worker crash

This commit is contained in:
Tobias Lins
2020-07-02 11:48:08 +02:00
parent ae8f650923
commit 1295bbea5d
3 changed files with 17 additions and 12 deletions

View File

@@ -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 (

View File

@@ -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) {

View File

@@ -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;
}