Skip to content

Commit

Permalink
fix: Promise.all handle error
Browse files Browse the repository at this point in the history
  • Loading branch information
devcatalin committed Apr 19, 2023
1 parent db3403a commit 14e87ad
Showing 1 changed file with 17 additions and 12 deletions.
29 changes: 17 additions & 12 deletions src/redux/thunks/setRootFolder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -112,27 +112,32 @@ export const setRootFolder = createAsyncThunk<
if (isGitRepo) {
thunkAPI.dispatch(setGitLoading(true));

Promise.all([getRepoInfo({path: rootFolder}), getChangedFiles({localPath: rootFolder, fileMap})])
.then(([repo, changedFiles]) => {
if (typeof repo !== 'object') {
Promise.allSettled([getRepoInfo({path: rootFolder}), getChangedFiles({localPath: rootFolder, fileMap})]).then(
([repo, changedFiles]) => {
if (repo.status === 'rejected' || changedFiles.status === 'rejected') {
const errorMessage =
'reason' in repo ? repo.reason : 'reason' in changedFiles ? changedFiles.reason : undefined;
log.error(errorMessage);
showGitErrorModal('Git error', errorMessage);
thunkAPI.dispatch(setGitLoading(false));
return;
}

if (typeof repo.value !== 'object') {
thunkAPI.dispatch(setRepo(undefined));
thunkAPI.dispatch(setGitLoading(false));
return;
}

thunkAPI.dispatch(setRepo(repo));
thunkAPI.dispatch(setChangedFiles(changedFiles));
thunkAPI.dispatch(setRepo(repo.value));
thunkAPI.dispatch(setChangedFiles(changedFiles.value));
thunkAPI.dispatch(setGitLoading(false));

if (repo.remoteRepo.authRequired) {
if (repo.value.remoteRepo.authRequired) {
showGitErrorModal('Authentication failed', undefined, `git remote show origin`, thunkAPI.dispatch);
}
})
.catch(err => {
log.error(err.message);
showGitErrorModal('Git error', err.message);
thunkAPI.dispatch(setGitLoading(false));
});
}
);
}

const endTime = new Date().getTime();
Expand Down

0 comments on commit 14e87ad

Please sign in to comment.