Skip to content

Commit c94b437

Browse files
committed
console loging remaining GitHub API calls and added a hardcoded fallback when rate limit got hit
1 parent 4056755 commit c94b437

File tree

1 file changed

+43
-2
lines changed

1 file changed

+43
-2
lines changed

src/App.svelte

Lines changed: 43 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,9 +126,50 @@
126126
async function getSqliteFiles() {
127127
const apiUrl =
128128
"https://api.github.com/repos/CNAG-Biomedical-Informatics/cbi-datahub/contents/sqlite";
129+
130+
console.log("Fetching SQLite files from:", apiUrl);
129131
try {
130132
const res = await fetch(apiUrl);
131-
if (!res.ok) return [];
133+
134+
// Check for GitHub rate limiting
135+
const remaining = res.headers.get("X-RateLimit-Remaining");
136+
const reset = res.headers.get("X-RateLimit-Reset");
137+
const resetDate = reset
138+
? new Date(parseInt(reset, 10) * 1000).toLocaleString()
139+
: "unknown";
140+
console.log(
141+
`GitHub API rate limit: ${remaining} remaining, resets at ${resetDate}`
142+
);
143+
if (res.status === 403 && remaining === "0") {
144+
const resetDate = reset ? new Date(parseInt(reset, 10) * 1000) : null;
145+
console.error(
146+
`GitHub API rate limit exceeded. ${
147+
resetDate
148+
? `Rate limit resets at ${resetDate.toLocaleString()}`
149+
: ""
150+
}`
151+
);
152+
return [];
153+
}
154+
155+
if (!res.ok) {
156+
console.error(`GitHub API returned status ${res.status}`);
157+
return [
158+
{
159+
name: "omim.db",
160+
type: "file",
161+
download_url:
162+
"https://raw.githubusercontent.com/CNAG-Biomedical-Informatics/cbi-datahub/main/sqlite/omim.db",
163+
},
164+
{
165+
name: "tcga.db",
166+
type: "file",
167+
download_url:
168+
"https://raw.githubusercontent.com/CNAG-Biomedical-Informatics/cbi-datahub/main/sqlite/tcga.db",
169+
},
170+
];
171+
}
172+
132173
const data = await res.json();
133174
return data
134175
.filter(
@@ -143,7 +184,7 @@
143184
`https://raw.githubusercontent.com/CNAG-Biomedical-Informatics/cbi-datahub/main/sqlite/${item.name}`,
144185
}));
145186
} catch (e) {
146-
console.error(e);
187+
console.error("Error fetching SQLite files:", e);
147188
return [];
148189
}
149190
}

0 commit comments

Comments
 (0)