Skip to content

Commit 151f59b

Browse files
committed
feat(cli): Console whoami better error handling
1 parent 46a1b5e commit 151f59b

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

templates/cli/lib/commands/generic.js.twig

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ const { Command } = require("commander");
33
const Client = require("../client");
44
const { sdkForConsole } = require("../sdks");
55
const { globalConfig, localConfig } = require("../config");
6-
const { actionRunner, success, parseBool, commandDescriptions, log, parse, drawTable } = require("../parser");
6+
const { actionRunner, success, parseBool, commandDescriptions, error, parse, drawTable } = require("../parser");
77
{% if sdk.test != "true" %}
88
const { questionsLogin, questionsListFactors, questionsMfaChallenge } = require("../questions");
99
const { accountUpdateMfaChallenge, accountCreateMfaChallenge, accountGet, accountCreateEmailPasswordSession, accountDeleteSession } = require("./account");
@@ -14,6 +14,11 @@ const whoami = new Command("whoami")
1414
helpWidth: process.stdout.columns || 80
1515
})
1616
.action(actionRunner(async () => {
17+
if (globalConfig.getEndpoint() === '' || globalConfig.getCookie() === '') {
18+
error("No user is signed in");
19+
return;
20+
}
21+
1722
let client = await sdkForConsole(false);
1823

1924
let account;
@@ -23,8 +28,9 @@ const whoami = new Command("whoami")
2328
sdk: client,
2429
parseOutput: false
2530
});
26-
} catch(error) {
27-
throw error;
31+
} catch (error) {
32+
error("No user is signed in");
33+
return;
2834
}
2935

3036
success("Signed in");
@@ -67,7 +73,7 @@ const login = new Command("login")
6773
sdk: client,
6874
parseOutput: false
6975
});
70-
} catch(error) {
76+
} catch (error) {
7177
if (error.response === 'user_more_factors_required') {
7278
const { factor } = await inquirer.prompt(questionsListFactors);
7379

@@ -191,10 +197,10 @@ const client = new Command("client")
191197
}));
192198

193199
module.exports = {
194-
{% if sdk.test != "true" %}
200+
{% if sdk.test != "true" %}
195201
whoami,
196202
login,
197203
logout,
198-
{% endif %}
204+
{% endif %}
199205
client
200206
};

0 commit comments

Comments
 (0)