Skip to content

Commit 2985820

Browse files
fix: Validate GitHub API directory files response (#680)
Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
1 parent b87885e commit 2985820

File tree

1 file changed

+13
-5
lines changed

1 file changed

+13
-5
lines changed

src/utils/documents.server.ts

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -595,11 +595,19 @@ async function fetchApiContentsRemote(
595595
const directoryFiles =
596596
(await directoryFilesResponse.json()) as Array<GitHubFile>
597597

598-
file.children = await buildFileTree(
599-
directoryFiles,
600-
depth + 1,
601-
`${parentPath}${file.path}/`,
602-
)
598+
if (!Array.isArray(directoryFiles)) {
599+
console.warn(
600+
`Expected an array of files from GitHub API for directory ${file.path}, but received:\n`,
601+
JSON.stringify(directoryFiles),
602+
)
603+
// Leave file.children undefined
604+
} else {
605+
file.children = await buildFileTree(
606+
directoryFiles,
607+
depth + 1,
608+
`${parentPath}${file.path}/`,
609+
)
610+
}
603611
}
604612

605613
result.push(file)

0 commit comments

Comments
 (0)