Skip to content

Commit

Permalink
fix(fetch): handle in case some error happend in Fetch
Browse files Browse the repository at this point in the history
  • Loading branch information
safeamiiir committed Jul 3, 2024
1 parent 6c1e9a1 commit 134f933
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
15 changes: 15 additions & 0 deletions aqueductcore/frontend/src/hooks/useUploadFile.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,18 @@ test('should handle failed file upload without error message', async () => {
id: 'upload_catch',
});
});

test('should handle fetch failure', async () => {
const mockError = new Error('Network Error');
(fetch as jest.Mock).mockRejectedValue(mockError);

const { result } = renderHook(() => useFileUpload('test-uuid'));

await act(async () => {
result.current.handleExperimentFileUpload(new File(['dummy content'], 'test.txt', { type: 'text/plain' }));
});

expect(toast.error).toHaveBeenCalledWith('Network Error', {
id: 'file_catch',
});
});
6 changes: 6 additions & 0 deletions aqueductcore/frontend/src/hooks/useUploadFile.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,12 @@ function useFileUpload(experimentUuid: ExperimentDataType['uuid']) {
});
}
})
// Somethings went wrong with the file
.catch((error) => {
toast.error(error.message ?? "Unable to upload file.", {
id: "file_catch",
});
});
}
return { handleExperimentFileUpload }
}
Expand Down

1 comment on commit 134f933

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coverage

Coverage Report
FileStmtsMissCoverMissing
aqueductcore/backend
   context.py34488%49–53, 60–61
   main.py19479%21–24, 31
   session.py13469%24–28
aqueductcore/backend/models
   extensions.py1511491%53, 56, 80–81, 88, 94, 96–97, 143, 177, 219, 247, 253, 261
   orm.py31197%58
aqueductcore/backend/routers
   files.py88298%169–170
   frontend.py241154%22–33, 37
aqueductcore/backend/routers/graphql
   mutations_schema.py58297%48, 135
   query_schema.py45296%66–68
   router.py11191%15
aqueductcore/backend/routers/graphql/mutations
   experiment_mutations.py24196%30
aqueductcore/backend/routers/graphql/resolvers
   experiment_resolver.py25292%28, 36
   tags_resolver.py25388%14, 44, 46
aqueductcore/backend/services
   experiment.py2203285%82, 111–124, 154, 188, 194, 240, 243, 268, 300, 348, 354, 383, 389, 406, 431, 438, 446, 476–482, 489–493, 505–508
   extensions_executor.py88891%39–42, 68, 83, 86, 152–158, 206
   validators.py33294%41, 46
aqueductcore/cli
   commands.py60788%32, 82–85, 94–98, 110–114
   exporter.py49198%71
   importer.py61198%90
TOTAL135110292% 

Tests Skipped Failures Errors Time
101 1 💤 0 ❌ 0 🔥 28.065s ⏱️

Please sign in to comment.