Skip to content

Commit 17540a9

Browse files
pavkoutgatzjames
andauthored
feat: Clean up Git notifications and status [INS-911] (#8891)
* feat: add new animation keyframes for up-loop and down-loop * fix(git): handle errors when checking for unpushed changes and improve permission error messages * fix(git): improve error handling and user feedback in Git sync dropdown * feat: add ProjectBranchName component with syncing status and pending changes indicators * feat: enhance SyncDropdown with ProjectBranchName component and improved sync status indicators * fix(git): add error handling to checkoutGitBranchAction for improved user feedback * fix(git): add error handling to checkoutGitBranchAction for improved user feedback * fix: reset initial state of ProjectBranchName to 'default' for correct sync status handling * refactor: remove showAlert calls for pull failure in GitProjectSyncDropdown * fix: replace showError with operationError state for improved error handling in SyncDropdown * fix: add success indicators to various Git actions for improved feedback * fix: update action return values to include success indicators for improved feedback * refactor: remove ProjectBranchName component to streamline dropdown functionality * feat: add Toaster component for improved toast notifications in Root * feat: add view transition animations for toast notifications * feat: enhance sync dropdown with toast notifications for Git actions * feat: add toast notifications for Git actions in sync dropdown * feat: implement Toast notification system with customizable content and styles * update notification styles * feat: improve error handling in Git actions with a centralized error message function * feat: update Git sync dropdown to display connection status and connect button when not synced --------- Co-authored-by: James Gatz <[email protected]>
1 parent 6b88463 commit 17540a9

10 files changed

+633
-244
lines changed

packages/insomnia/src/main/git-service.ts

Lines changed: 68 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,26 @@ type VCSAction =
6363
| 'setup'
6464
| 'clone';
6565

66+
function getErrorMessage(error: unknown): string {
67+
if (error instanceof Error) {
68+
const message = error.message || '';
69+
70+
// Check for network-related errors
71+
if (
72+
message.includes('net::ERR_UNEXPECTED') ||
73+
message.includes('net::ERR_INTERNET_DISCONNECTED') ||
74+
message.includes('net::ERR_NAME_NOT_RESOLVED')
75+
) {
76+
return 'A network error occurred.';
77+
}
78+
79+
// Default fallback
80+
return message;
81+
}
82+
83+
// Non-Error objects
84+
return 'Unknown Error';
85+
}
6686
export function vcsSegmentEventProperties(type: 'git', action: VCSAction, error?: string) {
6787
return { type, action, error };
6888
}
@@ -279,6 +299,7 @@ export const gitFetchAction = async ({ projectId, workspaceId }: { projectId: st
279299

280300
return {
281301
errors: [],
302+
success: true,
282303
};
283304
} catch (e) {
284305
console.error(e);
@@ -1300,7 +1321,7 @@ export const commitAndPushToGitRepoAction = async ({
13001321
errors: [`${err.message}, ${err.data.response}`],
13011322
};
13021323
}
1303-
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1324+
const errorMessage = getErrorMessage(err);
13041325

13051326
return { errors: [errorMessage] };
13061327
}
@@ -1349,7 +1370,7 @@ export const commitAndPushToGitRepoAction = async ({
13491370
errors: [`${err.message}, ${err.data.response}`],
13501371
};
13511372
}
1352-
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1373+
const errorMessage = getErrorMessage(err);
13531374

13541375
trackSegmentEvent(SegmentEvent.vcsAction, {
13551376
...vcsSegmentEventProperties('git', 'push', errorMessage),
@@ -1393,7 +1414,14 @@ export const createNewGitBranchAction = async ({
13931414
});
13941415

13951416
const { hasUncommittedChanges } = await getGitChanges(GitVCS);
1396-
const hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentials);
1417+
1418+
let hasUnpushedChanges = false;
1419+
try {
1420+
hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentials);
1421+
} catch (err) {
1422+
console.error('Error checking for unpushed changes', err);
1423+
hasUnpushedChanges = false;
1424+
}
13971425

13981426
await models.gitRepository.update(gitRepository, {
13991427
hasUncommittedChanges,
@@ -1417,6 +1445,7 @@ export const createNewGitBranchAction = async ({
14171445

14181446
export interface CheckoutGitBranchResult {
14191447
errors?: string[];
1448+
success?: boolean;
14201449
}
14211450

14221451
export const checkoutGitBranchAction = async ({
@@ -1439,7 +1468,15 @@ export const checkoutGitBranchAction = async ({
14391468
errors: [`${err.message}, ${err.data.response}`],
14401469
};
14411470
}
1471+
1472+
if (err instanceof Errors.CheckoutConflictError) {
1473+
return {
1474+
errors: [`${err.message} - Please commit or discard your changes before switching branches.`],
1475+
};
1476+
}
1477+
14421478
const errorMessage = err instanceof Error ? err.message : err;
1479+
14431480
return {
14441481
errors: [errorMessage],
14451482
};
@@ -1451,7 +1488,14 @@ export const checkoutGitBranchAction = async ({
14511488
const cachedGitLastCommitTime = author ? author.timestamp * 1000 : Date.now();
14521489

14531490
const { hasUncommittedChanges } = await getGitChanges(GitVCS);
1454-
const hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentials);
1491+
1492+
let hasUnpushedChanges = false;
1493+
try {
1494+
hasUnpushedChanges = await GitVCS.canPush(gitRepository.credentials);
1495+
} catch (err) {
1496+
console.error('Error checking for unpushed changes', err);
1497+
hasUnpushedChanges = false;
1498+
}
14551499

14561500
await models.gitRepository.update(gitRepository, {
14571501
cachedGitLastCommitTime,
@@ -1462,7 +1506,9 @@ export const checkoutGitBranchAction = async ({
14621506
});
14631507

14641508
await database.flushChanges(bufferId);
1465-
return {};
1509+
return {
1510+
success: true,
1511+
};
14661512
};
14671513

14681514
export const mergeGitBranch = async ({
@@ -1511,7 +1557,7 @@ export const mergeGitBranch = async ({
15111557
if (err instanceof MergeConflictError) {
15121558
return err.data;
15131559
}
1514-
let errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1560+
let errorMessage = getErrorMessage(err);
15151561

15161562
if (err instanceof Errors.HttpError) {
15171563
errorMessage = `${err.message}, ${err.data.response}`;
@@ -1548,13 +1594,14 @@ export const deleteGitBranchAction = async ({
15481594
});
15491595
return {};
15501596
} catch (err) {
1551-
const errorMessage = err instanceof Error ? err.message : 'Unknown error';
1597+
const errorMessage = getErrorMessage(err);
15521598
return { errors: [errorMessage] };
15531599
}
15541600
};
15551601

15561602
export interface PushToGitRemoteResult {
15571603
errors?: string[];
1604+
success?: boolean;
15581605
gitRepository?: GitRepository;
15591606
}
15601607

@@ -1576,12 +1623,20 @@ export const pushToGitRemoteAction = async ({
15761623
canPush = await GitVCS.canPush(gitRepository.credentials);
15771624
} catch (err) {
15781625
if (err instanceof Errors.HttpError) {
1626+
if (err.data.statusCode === 401 || err.data.statusCode === 403) {
1627+
// If we get a 401 or 403, it means that the user does not have permissions to push to this repository
1628+
return {
1629+
errors: [`${err.data.statusMessage}, it seems that you do not have permissions to push to this repository.`],
1630+
gitRepository,
1631+
};
1632+
}
1633+
15791634
return {
15801635
errors: [`${err.message}, ${err.data.response}`],
15811636
gitRepository,
15821637
};
15831638
}
1584-
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1639+
const errorMessage = getErrorMessage(err);
15851640

15861641
return { errors: [errorMessage], gitRepository };
15871642
}
@@ -1631,7 +1686,7 @@ export const pushToGitRemoteAction = async ({
16311686
gitRepository,
16321687
};
16331688
}
1634-
const errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1689+
const errorMessage = getErrorMessage(err);
16351690

16361691
trackSegmentEvent(SegmentEvent.vcsAction, {
16371692
...vcsSegmentEventProperties('git', 'push', errorMessage),
@@ -1644,7 +1699,9 @@ export const pushToGitRemoteAction = async ({
16441699
};
16451700
}
16461701

1647-
return {};
1702+
return {
1703+
success: true,
1704+
};
16481705
};
16491706

16501707
export async function pullFromGitRemote({ projectId, workspaceId }: { projectId: string; workspaceId?: string }) {
@@ -1675,7 +1732,7 @@ export async function pullFromGitRemote({ projectId, workspaceId }: { projectId:
16751732
return err.data;
16761733
}
16771734

1678-
let errorMessage = err instanceof Error ? err.message : 'Unknown Error';
1735+
let errorMessage = getErrorMessage(err);
16791736

16801737
if (err instanceof Errors.HttpError) {
16811738
errorMessage = `${err.message}, ${err.data.response}`;

0 commit comments

Comments
 (0)