From 52bd6fa381e70516492a49ab79f4608fb30c573f Mon Sep 17 00:00:00 2001 From: Helder Oliveira Date: Wed, 6 Nov 2024 17:38:18 +0000 Subject: [PATCH] =?UTF-8?q?chore:=20=F0=9F=A4=96=20handle=20authentication?= =?UTF-8?q?=20initialisation=20error=20gracefully=20and=20exit=20none-zero?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/guards/sdkGuard.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/src/guards/sdkGuard.ts b/src/guards/sdkGuard.ts index d1a40469..60c5eb50 100644 --- a/src/guards/sdkGuard.ts +++ b/src/guards/sdkGuard.ts @@ -1,10 +1,11 @@ -import { UnauthenticatedError } from '@fleek-platform/errors'; import { FleekSdk, PersonalAccessTokenService } from '@fleek-platform/sdk/node'; import { getDefined } from '../defined'; import { output } from '../cli'; import { config } from '../config'; import { loginGuard } from './loginGuard'; +import { t } from '../utils/translation'; + import type { Action, SdkGuardedFunction } from './types'; type SdkGuardArgs = SdkGuardedFunction; @@ -14,7 +15,8 @@ export const getSdkClient = () => { const projectId = config.projectId.get(); if (!personalAccessToken) { - return; + output.error(t('missingPersonalAccessToken')); + process.exit(1); } const accessTokenService = new PersonalAccessTokenService({ @@ -38,7 +40,8 @@ export const sdkGuard = (func: SdkGuardArgs): Action => { const sdk = getSdkClient(); if (!sdk) { - throw new UnauthenticatedError(); + output.error(t('failedAuthentication')); + process.exit(1); } try { @@ -46,10 +49,11 @@ export const sdkGuard = (func: SdkGuardArgs): Action => { } catch (error) { if (error instanceof Error) { output.error(error?.toString()); - return; + process.exit(1); } output.error(`Unknown Error: ${JSON.stringify(error)}`); + process.exit(1); } }; };