Skip to content

Commit bc6432d

Browse files
handled if else condition (#1529)
1 parent 286acc5 commit bc6432d

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

frontend/src/components/Graph/GraphViewModal.tsx

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,13 +139,15 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
139139
}
140140
return nodeRelationshipData;
141141
} catch (error: any) {
142+
if (error.code === 'ERR_CANCELED' || error.name === 'CanceledError' || error.name === 'AbortError') {
143+
const cancelErr = new Error('Request was cancelled.');
144+
(cancelErr as any).isCancelled = true;
145+
throw cancelErr;
146+
}
142147
console.error('Error fetching graph data:', error);
143148
if (error.code === 'ECONNABORTED' || error.message?.includes('timeout')) {
144149
throw new Error('Request timed out. The dataset might be too large to preview. Try selecting fewer documents.');
145150
}
146-
if (error.name === 'AbortError') {
147-
throw new Error('Request was cancelled.');
148-
}
149151
throw new Error(error.response?.data?.error || error.message || 'Failed to fetch graph data. Please try again.');
150152
}
151153
}, [viewPoint, selectedRows, graphQuery, inspectedName, userCredentials]);
@@ -203,6 +205,10 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
203205
setDisableRefresh(false);
204206
setShowLargeDatasetWarning(false);
205207
} catch (error: any) {
208+
if (error?.isCancelled) {
209+
setLoading(false);
210+
return;
211+
}
206212
console.error('Graph API error:', error);
207213
setLoading(false);
208214
setStatus('danger');
@@ -213,7 +219,14 @@ const GraphViewModal: React.FunctionComponent<GraphViewModalProps> = ({
213219
useEffect(() => {
214220
if (open) {
215221
setLoading(true);
222+
setStatus('unknown');
223+
setStatusMessage('');
216224
setGraphType([]);
225+
setNode([]);
226+
setRelationship([]);
227+
setAllNodes([]);
228+
setAllRelationships([]);
229+
setScheme({});
217230
if (viewPoint === graphLabels.showGraphView && selectedRows && selectedRows.length > 8) {
218231
setShowLargeDatasetWarning(true);
219232
}

frontend/src/services/GraphQuery.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,10 @@ export const graphQueryAPI = async (
1818
timeout: 120000,
1919
});
2020
return response;
21-
} catch (error) {
21+
} catch (error: any) {
22+
if (error?.code === 'ERR_CANCELED' || error?.name === 'CanceledError') {
23+
throw error;
24+
}
2225
console.error('Error getting the Nodes or Relationships:', error);
2326
throw error;
2427
}

0 commit comments

Comments
 (0)