Skip to content

Commit

Permalink
Update contentListUpdater.js to solve the exception: Data is not iter…
Browse files Browse the repository at this point in the history
…able.

 • Error fetching file list: TypeError: data is not iterable
 at fetchKotlinFiles (contentListUpdater.js:15:32)
 at async HTMLDocument. <anonymous> (contentListUpdater.js: 66:5)
 fetchKotlinFiles @ contentListUpdater.js:24
  • Loading branch information
sagarpatel288 committed Oct 7, 2024
1 parent 96d2363 commit fa255a4
Showing 1 changed file with 14 additions and 7 deletions.
21 changes: 14 additions & 7 deletions contentListUpdater.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,15 +10,22 @@ document.addEventListener('DOMContentLoaded', async () => {
async function fetchKotlinFiles(path = '') {
try {
const response = await fetch(`https://api.github.com/repos/${username}/${repo}/contents/${path}`);
if (!response.ok) {
throw new Error('Network response was not ok');
}
const data = await response.json();

for (const item of data) {
if (item.type === 'dir') {
// Recursively fetch Kotlin files in subdirectories
await fetchKotlinFiles(item.path);
} else if (item.type === 'file' && item.name.endsWith('.kt')) {
kotlinFiles.push({ name: item.name, url: item.html_url, date: new Date(item.git_url) });
if (Array.isArray(data)) {
for (const item of data) {
if (item.type === 'dir') {
// Recursively fetch Kotlin files in subdirectories
await fetchKotlinFiles(item.path);
} else if (item.type === 'file' && item.name.endsWith('.kt')) {
kotlinFiles.push({ name: item.name, url: item.html_url, date: new Date(item.git_url) });
}
}
} else {
console.error('Unexpected data format:', data);
}
} catch (error) {
console.error('Error fetching file list:', error);
Expand Down Expand Up @@ -65,4 +72,4 @@ document.addEventListener('DOMContentLoaded', async () => {
// Start fetching Kotlin files from the root of the repository
await fetchKotlinFiles();
renderFileList(kotlinFiles);
});
});

0 comments on commit fa255a4

Please sign in to comment.