Skip to content

Commit

Permalink
fix: fetch json failed catch
Browse files Browse the repository at this point in the history
  • Loading branch information
Yanyan-Wang committed Sep 6, 2023
1 parent 7049ada commit c0be31a
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@antv/gi-assets-xlab",
"version": "0.1.29",
"version": "0.1.30",
"description": "A G6VP asset for X-lab.",
"keywords": [
"G6VP",
Expand Down
2 changes: 1 addition & 1 deletion src/components/Search/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ const XlabSearch = props => {
});
};

const queryNeighbors = (nodes, types, limit, resGraphData, callback) => {
const queryNeighbors = (nodes, types, limit, resGraphData, callback = (resData: any) => {}) => {
if (!neighborsService || !nodes?.length || !types?.length) return [];
return types.map(async type => {
const res = await neighborsService({
Expand Down
21 changes: 14 additions & 7 deletions src/components/XlabPropertiesPanel/Component.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -131,13 +131,16 @@ const XlabPropertiesPanel = props => {

const userNode = getTypeNodeModels(models, ['github_user']) || [];
const infos = {};
const userInfoPromises: Promise<any>[] = userNode.map(async model => {
const response = await fetch(`https://oss.x-lab.info/open_digger/github/${model.name}/meta.json`);
const fetchedData = await response.json();
const { bio, location, company } = fetchedData.info;
infos[model.id] = { 'πŸ“ bio': bio, 'πŸ“ location': location, '🏠 company': company };
return fetchedData;
});
const userInfoPromises: Promise<any>[] = userNode
.map(async model => {
const response = await fetch(`https://oss.x-lab.info/open_digger/github/${model.name}/meta.json`);
if (response.ok === false) return;
const fetchedData = await response.json();
const { bio, location, company } = fetchedData.info;
infos[model.id] = { 'πŸ“ bio': bio, 'πŸ“ location': location, '🏠 company': company };
return fetchedData;
})
.filter(Boolean);

const staticPromises: Promise<any>[] = repoUserModels
.map(async ({ id, name }) => {
Expand All @@ -163,6 +166,9 @@ const XlabPropertiesPanel = props => {
}
try {
const response = await fetch(`https://oss.x-lab.info/open_digger/github/${name}/${key}.json`);
if (response.ok === false) {
return;
}
const fetchedData = await response.json();
cachedStateicData[modelKey] = cachedStateicData[modelKey] || {};
cachedStateicData[modelKey][key] = fetchedData;
Expand All @@ -184,6 +190,7 @@ const XlabPropertiesPanel = props => {
}
});
})
.filter(Boolean)
.flat();
await Promise.all([...promises, ...userInfoPromises, ...staticPromises]);

Expand Down

0 comments on commit c0be31a

Please sign in to comment.