Skip to content

Commit

Permalink
fix: ds-437 remove untreated errors throws
Browse files Browse the repository at this point in the history
Relats to JIRA: DISCOVERY-437
  • Loading branch information
nicolearagao committed Oct 16, 2024
1 parent 6a08ef7 commit 535f18e
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 10 deletions.
4 changes: 2 additions & 2 deletions src/helpers/queryHelpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ export const useServiceQuery = <TItem, TColumnKey extends string, TSortableColum
setRefreshTime?.(new Date());
return response.data;
} catch (error) {
console.error(error);
throw error; // You can choose to throw the error or return a default value here
console.log('Error during data fetching:', error);
return { count: 0, results: [] } as ServiceQueryResult<TItem>;
}
}
});
18 changes: 18 additions & 0 deletions src/hooks/__tests__/__snapshots__/useScanApi.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -413,6 +413,24 @@ exports[`useRunScanApi should handle errors while attempting to run a scan: runS
]
`;

exports[`useRunScanApi should handle missing scan ID and trigger custom error: runScans, no ID returned 1`] = `
[
[
{
"title": "t([
"toast-notifications.description",
{
"context": "scan-report_play_error",
"name": "Lorem",
"message": "No ID returned\\nThe scan or rescan operation did not return an ID."
}
])",
"variant": "danger",
},
],
]
`;

exports[`useRunScanApi should handle success while attempting to run a scan: runScans, success 1`] = `
[
[
Expand Down
8 changes: 8 additions & 0 deletions src/hooks/__tests__/useScanApi.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -400,6 +400,14 @@ describe('useRunScanApi', () => {

expect(mockOnAddAlert.mock.calls).toMatchSnapshot('callbackError');
});

it('should handle missing scan ID and trigger custom error', async () => {
const { runScans } = hookResult;
mockCreateScan.mockResolvedValue({});

await runScans({ name: 'Lorem' });
expect(mockOnAddAlert.mock.calls).toMatchSnapshot('runScans, no ID returned');
});
});

describe('useDownloadReportApi', () => {
Expand Down
12 changes: 11 additions & 1 deletion src/hooks/useScanApi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,17 @@ const useRunScanApi = (
const scanId = (isRescan && payload?.id?.toString()) || (await createScans(payload))?.id?.toString();

if (!scanId) {
throw new Error(`${(isRescan && 'Rescan') || 'Scan'} failed, no ID returned`);
console.log(`${(isRescan && 'Rescan') || 'Scan'} failed, no ID returned`);
const customError: AxiosError<ApiScanErrorType> = {
isAxiosError: false,
response: {
data: {
message: 'No ID returned',
detail: 'The scan or rescan operation did not return an ID.'
}
}
} as AxiosError<ApiScanErrorType>;
return callbackError(customError, payload.name);
}

await apiCall(scanId);
Expand Down
15 changes: 8 additions & 7 deletions tests/__snapshots__/code.test.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"components/viewLayout/viewLayoutToolbar.tsx:65: console.log('selected', value);",
"components/viewLayout/viewLayoutToolbar.tsx:73: console.log('selected', value);",
"helpers/queryHelpers.ts:70: console.log(\`Query: \`, query);",
"helpers/queryHelpers.ts:75: console.error(error);",
"helpers/queryHelpers.ts:75: console.log('Error during data fetching:', error);",
"hooks/useCredentialApi.ts:81: console.log(missingCredsMsg);",
"hooks/useCredentialApi.ts:99: console.log(missingCredsMsg);",
"hooks/useCredentialApi.ts:145: console.error(error);",
Expand All @@ -17,12 +17,13 @@ exports[`General code checks should only have specific console.[warn|log|info|er
"hooks/useLoginApi.ts:137: console.error(error);",
"hooks/useLoginApi.ts:166: console.error('Invalid token, unable to parse format');",
"hooks/useScanApi.ts:67: console.error(error);",
"hooks/useScanApi.ts:140: console.error(error);",
"hooks/useScanApi.ts:186: console.log(missingScansMsg);",
"hooks/useScanApi.ts:220: console.error(error);",
"hooks/useScanApi.ts:274: console.error(error);",
"hooks/useScanApi.ts:347: console.error(error);",
"hooks/useScanApi.ts:392: console.error(error);",
"hooks/useScanApi.ts:131: console.log(\`\${(isRescan && 'Rescan') || 'Scan'} failed, no ID returned\`);",
"hooks/useScanApi.ts:150: console.error(error);",
"hooks/useScanApi.ts:196: console.log(missingScansMsg);",
"hooks/useScanApi.ts:230: console.error(error);",
"hooks/useScanApi.ts:284: console.error(error);",
"hooks/useScanApi.ts:357: console.error(error);",
"hooks/useScanApi.ts:402: console.error(error);",
"hooks/useSourceApi.ts:63: console.log(missingSourcesMsg);",
"hooks/useSourceApi.ts:81: console.log(missingSourcesMsg);",
"hooks/useSourceApi.ts:127: console.error(error);",
Expand Down

0 comments on commit 535f18e

Please sign in to comment.