Skip to content

Commit 699b24f

Browse files
committed
Minor code shuffle
1 parent f30d77f commit 699b24f

1 file changed

Lines changed: 30 additions & 30 deletions

File tree

src/utils/api.mts

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,35 @@ import type {
1919

2020
const NO_ERROR_MESSAGE = 'No error message returned'
2121

22+
// The Socket API server that should be used for operations.
23+
export function getDefaultApiBaseUrl(): string | undefined {
24+
const baseUrl =
25+
// Lazily access constants.ENV.SOCKET_CLI_API_BASE_URL.
26+
constants.ENV.SOCKET_CLI_API_BASE_URL || getConfigValueOrUndef('apiBaseUrl')
27+
if (isNonEmptyString(baseUrl)) {
28+
return baseUrl
29+
}
30+
// Lazily access constants.API_V0_URL.
31+
const API_V0_URL = constants.API_V0_URL
32+
return API_V0_URL
33+
}
34+
35+
export async function getErrorMessageForHttpStatusCode(code: number) {
36+
if (code === 400) {
37+
return 'One of the options passed might be incorrect'
38+
}
39+
if (code === 403 || code === 401) {
40+
return 'Your Socket API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API token you are logged in with'
41+
}
42+
if (code === 404) {
43+
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.'
44+
}
45+
if (code === 500) {
46+
return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.'
47+
}
48+
return `Server responded with status code ${code}`
49+
}
50+
2251
export type HandleApiCallOptions = {
2352
desc?: string | undefined
2453
spinner?: Spinner | undefined
@@ -142,35 +171,6 @@ export async function handleApiCallNoSpinner<T extends SocketSdkOperations>(
142171
}
143172
}
144173

145-
export async function getErrorMessageForHttpStatusCode(code: number) {
146-
if (code === 400) {
147-
return 'One of the options passed might be incorrect'
148-
}
149-
if (code === 403 || code === 401) {
150-
return 'Your Socket API token may not have the required permissions for this command or you might be trying to access (data from) an organization that is not linked to the API token you are logged in with'
151-
}
152-
if (code === 404) {
153-
return 'The requested Socket API endpoint was not found (404) or there was no result for the requested parameters. If unexpected, this could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.'
154-
}
155-
if (code === 500) {
156-
return 'There was an unknown server side problem with your request. This ought to be temporary. Please let us know if this problem persists.'
157-
}
158-
return `Server responded with status code ${code}`
159-
}
160-
161-
// The Socket API server that should be used for operations.
162-
export function getDefaultApiBaseUrl(): string | undefined {
163-
const baseUrl =
164-
// Lazily access constants.ENV.SOCKET_CLI_API_BASE_URL.
165-
constants.ENV.SOCKET_CLI_API_BASE_URL || getConfigValueOrUndef('apiBaseUrl')
166-
if (isNonEmptyString(baseUrl)) {
167-
return baseUrl
168-
}
169-
// Lazily access constants.API_V0_URL.
170-
const API_V0_URL = constants.API_V0_URL
171-
return API_V0_URL
172-
}
173-
174174
export async function queryApi(path: string, apiToken: string) {
175175
const baseUrl = getDefaultApiBaseUrl() || ''
176176
if (!baseUrl) {
@@ -197,7 +197,7 @@ export async function queryApiSafeText(
197197
ok: false,
198198
message: 'Authentication Error',
199199
cause:
200-
'User must be authenticated to run this command. To log in, run the command `socket login` and enter your Socket API token.',
200+
'User must be authenticated to run this command. Run `socket login` and enter your Socket API token.',
201201
}
202202
}
203203

0 commit comments

Comments
 (0)