Skip to content

Commit

Permalink
Refactor to add auth error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
charliegerard committed Aug 21, 2024
1 parent fc3f2aa commit 7d1f26f
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions src/commands/dependencies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import { printFlagList } from '../utils/formatting'
import { getDefaultKey, setupSdk } from '../utils/sdk'

import type { CliSubcommand } from '../utils/meow-with-subcommands'

Check warning on line 15 in src/commands/dependencies.ts

View workflow job for this annotation

GitHub Actions / Linting / Test (20, ubuntu-latest)

There should be at least one empty line between import groups
import type { Ora } from 'ora'
import { AuthError } from '../utils/errors'

Check warning on line 16 in src/commands/dependencies.ts

View workflow job for this annotation

GitHub Actions / Linting / Test (20, ubuntu-latest)

`../utils/errors` import should occur before import of `../utils/formatting`

export const dependencies: CliSubcommand = {
description:
Expand All @@ -23,9 +23,7 @@ export const dependencies: CliSubcommand = {

const input = setupCommand(name, dependencies.description, argv, importMeta)
if (input) {
const spinnerText = 'Searching dependencies...'
const spinner = ora(spinnerText).start()
await searchDeps(input, spinner)
await searchDeps(input)
}
}
}
Expand Down Expand Up @@ -100,10 +98,17 @@ function setupCommand(
}

async function searchDeps(
{ limit, offset, outputJson }: CommandContext,
spinner: Ora
{ limit, offset, outputJson }: CommandContext
): Promise<void> {
const socketSdk = await setupSdk(getDefaultKey())
const apiKey = getDefaultKey()
if(!apiKey){
throw new AuthError("User must be authenticated to run this command. To log in, run the command `socket login` and enter your API key.")
}
const spinnerText = 'Searching dependencies...'
const spinner = ora(spinnerText).start()

const socketSdk = await setupSdk(apiKey)

const result = await handleApiCall(
socketSdk.searchDependencies({ limit, offset }),
'Searching dependencies'
Expand Down

0 comments on commit 7d1f26f

Please sign in to comment.