Skip to content

Commit

Permalink
chore: 🤖 handle authentication initialisation error gracefully and ex…
Browse files Browse the repository at this point in the history
…it none-zero
  • Loading branch information
heldrida committed Nov 6, 2024
1 parent 7bad30b commit 52bd6fa
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions src/guards/sdkGuard.ts
Original file line number Diff line number Diff line change
@@ -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<T> = SdkGuardedFunction<T>;
Expand All @@ -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({
Expand All @@ -38,18 +40,20 @@ export const sdkGuard = <T>(func: SdkGuardArgs<T>): Action<T> => {
const sdk = getSdkClient();

if (!sdk) {
throw new UnauthenticatedError();
output.error(t('failedAuthentication'));
process.exit(1);
}

try {
await func({ sdk, args });
} catch (error) {
if (error instanceof Error) {
output.error(error?.toString());
return;
process.exit(1);
}

output.error(`Unknown Error: ${JSON.stringify(error)}`);
process.exit(1);
}
};
};

0 comments on commit 52bd6fa

Please sign in to comment.