Skip to content

Commit 461e538

Browse files
committed
add debug log
1 parent 44b53cb commit 461e538

1 file changed

Lines changed: 16 additions & 0 deletions

File tree

src/scripts/fetch-comments.js

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,22 @@ async function fetchDiscussions() {
6969
});
7070

7171
const data = await response.json();
72+
73+
// Check for API errors in the response
74+
if (data.errors) {
75+
console.error("GitHub API returned errors:", JSON.stringify(data.errors, null, 2));
76+
throw new Error("Failed to fetch discussions due to API errors.");
77+
}
78+
79+
// Check for unexpected data structure
80+
if (!data.data || !data.data.repository || !data.data.repository.discussionCategory) {
81+
console.error("Unexpected data structure from GitHub API:", JSON.stringify(data, null, 2));
82+
if (data.data && data.data.repository && !data.data.repository.discussionCategory) {
83+
throw new Error(`Could not find the discussion category: '${DISCUSSION_CATEGORY_NAME}'. Please check the name.`);
84+
}
85+
throw new Error("Unexpected data structure received from GitHub API.");
86+
}
87+
7288
return data.data.repository.discussionCategory.discussions.nodes;
7389
}
7490

0 commit comments

Comments
 (0)