Skip to content

Commit 18b12fb

Browse files
Fix linter only
1 parent a7d3801 commit 18b12fb

File tree

4 files changed

+46
-10
lines changed

4 files changed

+46
-10
lines changed

.env.development

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# GitHub API Token for notebook fetching (optional but recommended)
2+
GITHUB_TOKEN=your_github_token_here
3+
14
KEYCLOAK_ISSUER=https://staging.openbraininstitute.org/auth/realms/SBO
25
KEYCLOAK_CLIENT_ID=obp-core-web-app-dev
36
KEYCLOAK_CLIENT_SECRET=dummy-secret

src/ui/segments/notebooks/table.tsx

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import { ConfigProvider } from 'antd';
44

5-
import { useState } from 'react';
5+
import { useEffect, useRef, useState } from 'react';
66

77
import { LoadingOutlined } from '@ant-design/icons';
88
import Table from 'antd/es/table';
@@ -44,24 +44,33 @@ function NotebookTable({
4444
const [currentNotebook, setCurrentNotebook] = useState<Notebook | null>(null);
4545
const [display, setDisplay] = useState<'notebook' | 'readme' | null>(null);
4646

47-
if (serverError)
47+
// Trigger notifications after render to avoid setState during render warnings
48+
const hasWarnedFailedRef = useRef(false);
49+
50+
useEffect(() => {
51+
if (!serverError) return;
4852
notification.error({
4953
message: serverError,
5054
key: 'notebooks-server-error',
5155
placement: 'topRight',
5256
});
57+
}, [serverError, notification]);
5358

54-
const resetModal = () => {
55-
setCurrentNotebook(null);
56-
setDisplay(null);
57-
};
58-
59-
if (failed && failed.length)
59+
useEffect(() => {
60+
if (!failed || failed.length === 0) return;
61+
if (hasWarnedFailedRef.current) return; // prevent duplicate toast on re-renders
6062
notification.warning({
6163
message:
6264
"Failed to fetch some repositories, ensure they're public and contain valid metadata for each notebook",
6365
placement: 'topRight',
6466
});
67+
hasWarnedFailedRef.current = true;
68+
}, [failed, notification]);
69+
70+
const resetModal = () => {
71+
setCurrentNotebook(null);
72+
setDisplay(null);
73+
};
6574

6675
const { filteredColumns, toggleColumn, isColumnHidden } = useToggleColumns(columns);
6776

src/util/virtual-lab/fetchNotebooks.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,17 @@ export default async function fetchNotebooks(repoUrl: string, withDate = false)
3737
});
3838

3939
if (!response.ok) {
40-
throw new Error(`Cannot fetch the repository ${repoUrl}, ensure the repository is public.`);
40+
if (response.status === 403) {
41+
const errorData = await response.json().catch(() => ({ message: 'Unknown error' }));
42+
if (errorData.message?.includes('rate limit')) {
43+
throw new Error(
44+
`GitHub API rate limit exceeded when fetching ${repoUrl}. Please add a GITHUB_TOKEN to your environment or wait before trying again.`
45+
);
46+
}
47+
}
48+
throw new Error(
49+
`Cannot fetch the repository ${repoUrl}, ensure the repository is public. (Status: ${response.status})`
50+
);
4151
}
4252

4353
const tree: { tree: Item[] } = await response.json();

src/util/virtual-lab/github.ts

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,21 @@ export async function fetchGithubFile(url: string) {
5656
const response = await fetch(url, options);
5757

5858
if (!response.ok) {
59-
throw new Error(`Failed to fetch file ${url}`);
59+
if (response.status === 403) {
60+
const errorData = await response.json().catch(() => ({ message: 'Unknown error' }));
61+
if (errorData.message?.includes('rate limit')) {
62+
throw new Error(
63+
`GitHub API rate limit exceeded. Please add a GITHUB_TOKEN to your environment or wait before trying again. ${url}`
64+
);
65+
}
66+
throw new Error(
67+
`GitHub API access forbidden. Check permissions or add GITHUB_TOKEN to environment. ${url}`
68+
);
69+
}
70+
if (response.status === 404) {
71+
throw new Error(`GitHub file not found: ${url}`);
72+
}
73+
throw new Error(`Failed to fetch file ${url} (Status: ${response.status})`);
6074
}
6175

6276
const data = await response.json();

0 commit comments

Comments
 (0)