mirror of
https://github.com/balena-io/balena-cli.git
synced 2025-06-20 08:43:44 +00:00
Error handling: add ExpectedError type as alternative to exitWithExpectedError()
Change-type: patch Signed-off-by: Paulo Castro <paulo@balena.io>
This commit is contained in:
@ -22,6 +22,7 @@ import _ = require('lodash');
|
||||
import _form = require('resin-cli-form');
|
||||
import _visuals = require('resin-cli-visuals');
|
||||
|
||||
import { NotLoggedInError } from '../errors';
|
||||
import messages = require('./messages');
|
||||
import validation = require('./validation');
|
||||
|
||||
@ -77,16 +78,28 @@ export function authenticate(options: {}): Bluebird<void> {
|
||||
});
|
||||
}
|
||||
|
||||
export async function exitIfNotLoggedIn(): Promise<void> {
|
||||
export async function checkLoggedIn(): Promise<void> {
|
||||
const balena = getBalenaSdk();
|
||||
if (!(await balena.auth.isLoggedIn())) {
|
||||
exitWithExpectedError(stripIndent`
|
||||
throw new NotLoggedInError(stripIndent`
|
||||
You have to log in to continue
|
||||
Run the following command to go through the login wizard:
|
||||
$ balena login`);
|
||||
}
|
||||
}
|
||||
|
||||
export async function exitIfNotLoggedIn(): Promise<void> {
|
||||
try {
|
||||
await checkLoggedIn();
|
||||
} catch (error) {
|
||||
if (error instanceof NotLoggedInError) {
|
||||
exitWithExpectedError(error);
|
||||
} else {
|
||||
throw error;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function askLoginType() {
|
||||
return getForm().ask({
|
||||
message: 'How would you like to login?',
|
||||
|
Reference in New Issue
Block a user