Skip to content

Commit

Permalink
feat: add better error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Jnig committed Sep 13, 2024
1 parent 6af9283 commit bf56182
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/config.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,16 @@ export async function writeProfile(profileName, profileConfig) {
await writeFile(configFile, ini.stringify(config));
}

export async function getSession(sessioName) {
export async function getSession(sessionName) {
const config = ini.parse(await readFile(configFile, "utf-8"));
const key = ("sso-session " + sessionName).trim();

return config["sso-session " + sessioName];
if (!config[key]) {
console.log(`Key "${key}" not found in ${configFile}`);
process.exit(1);
}

return config[key];
}

export async function getCurrentSession() {
Expand Down Expand Up @@ -137,7 +143,12 @@ export async function readAccountCache(sessionName) {
} catch (_) {
return [];
}
return JSON.parse(await readFile(cacheFile, "utf8"));

try {
return JSON.parse(await readFile(cacheFile, "utf8"));
} catch (_) {
return [];
}
}

export async function writeAccountCache(sessionName, accounts) {
Expand Down

0 comments on commit bf56182

Please sign in to comment.