diff --git a/src/shared/options/getGitHub.ts b/src/shared/options/getGitHub.ts index 6f3f573e1..1ce600403 100644 --- a/src/shared/options/getGitHub.ts +++ b/src/shared/options/getGitHub.ts @@ -7,16 +7,24 @@ export interface GitHub { } export async function getGitHub(): Promise { - const auth = await getGitHubAuthToken(); + try { + const auth = await getGitHubAuthToken(); - if (!auth.succeeded) { + if (!auth.succeeded) { + throw new Error("GitHub authentication failed.", { + cause: auth.error, + }); + } + + const octokit = new Octokit({ auth: auth.token }); + + return { auth: auth.token, octokit }; + } catch (error) { throw new Error( "Couldn't authenticate with GitHub. Either log in with `gh auth login` (https://cli.github.com) or set a GH_TOKEN environment variable.", - { cause: auth.error }, + { + cause: error, + }, ); } - - const octokit = new Octokit({ auth: auth.token }); - - return { auth: auth.token, octokit }; }