Skip to content

Commit 8499369

Browse files
ShellishackCopilot
andauthored
Update npm-packages/cli/source/lib/token.ts
Co-authored-by: Copilot <[email protected]>
1 parent e3cc979 commit 8499369

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

npm-packages/cli/source/lib/token.ts

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,15 @@ export function getToken() {
2626
const configDir = path.join(os.homedir(), '.pulse-editor');
2727
const configFile = path.join(configDir, 'config.json');
2828
if (fs.existsSync(configFile)) {
29-
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
30-
if (config.accessToken) {
31-
return config.accessToken as string;
32-
}
29+
try {
30+
const config = JSON.parse(fs.readFileSync(configFile, 'utf8'));
31+
if (config.accessToken) {
32+
return config.accessToken as string;
33+
}
34+
} catch (error) {
35+
console.error('Failed to parse config.json:', error);
36+
// Return undefined if JSON parsing fails
37+
return undefined;
3338
}
3439

3540
// If not found, return undefined

0 commit comments

Comments
 (0)