Skip to content

Commit f47e461

Browse files
authored
feat(errors): safe storage bad credentials (#2216)
Signed-off-by: Adam Setch <[email protected]>
1 parent 41670e2 commit f47e461

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

src/renderer/utils/api/errors.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import { AxiosError, type AxiosResponse } from 'axios';
22

3+
import { EVENTS } from '../../../shared/events';
4+
35
import type { Link } from '../../types';
46
import type { GitHubRESTError } from '../../typesGitHub';
57
import { Errors } from '../errors';
@@ -93,6 +95,18 @@ describe('renderer/utils/api/errors.ts', () => {
9395
});
9496
});
9597

98+
it('bad credentials - safe storage', async () => {
99+
const mockError: Partial<AxiosError<GitHubRESTError>> = {
100+
message: `Error invoking remote method '${EVENTS.SAFE_STORAGE_DECRYPT}': Error: Error while decrypting the ciphertext provided to safeStorage.decryptString. Ciphertext does not appear to be encrypted.`,
101+
};
102+
103+
const result = determineFailureType(
104+
mockError as AxiosError<GitHubRESTError>,
105+
);
106+
107+
expect(result).toBe(Errors.BAD_CREDENTIALS);
108+
});
109+
96110
it('unknown error', async () => {
97111
const mockError: Partial<AxiosError<GitHubRESTError>> = {
98112
code: 'anything',

src/renderer/utils/api/errors.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ export function determineFailureType(
1313
return Errors.NETWORK;
1414
}
1515

16+
if (err.message?.includes('safeStorage')) {
17+
return Errors.BAD_CREDENTIALS;
18+
}
19+
1620
if (code !== AxiosError.ERR_BAD_REQUEST) {
1721
return Errors.UNKNOWN;
1822
}

0 commit comments

Comments
 (0)