Skip to content

Commit dede5b8

Browse files
authored
Fix getting the API base url and 404 error message (#388)
1 parent ae27a23 commit dede5b8

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/utils/api.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@ import type {
1414
SocketSdkOperations
1515
} from '@socketsecurity/sdk'
1616

17-
const { SOCKET_SECURITY_API_BASE_URL } = constants
18-
1917
export function handleUnsuccessfulApiResponse<T extends SocketSdkOperations>(
2018
_name: T,
2119
sockSdkError: SocketSdkErrorType<T>
@@ -54,8 +52,10 @@ export async function handleApiError(code: number) {
5452
return 'One of the options passed might be incorrect.'
5553
} else if (code === 403) {
5654
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.'
55+
} else if (code === 404) {
56+
return 'The requested Socket API endpoint was not found (404). This could be a temporary problem caused by an incident or a bug in the CLI. If the problem persists please let us know.'
5757
} else {
58-
;`Server responded with status code ${code}`
58+
return `Server responded with status code ${code}`
5959
}
6060
}
6161

@@ -67,9 +67,13 @@ export function getLastFiveOfApiToken(token: string): string {
6767
// The API server that should be used for operations.
6868
export function getDefaultApiBaseUrl(): string | undefined {
6969
const baseUrl =
70-
// Lazily access constants.ENV[SOCKET_SECURITY_API_BASE_URL].
71-
constants.ENV[SOCKET_SECURITY_API_BASE_URL] || getConfigValue('apiBaseUrl')
72-
return isNonEmptyString(baseUrl) ? baseUrl : undefined
70+
process.env['SOCKET_SECURITY_API_BASE_URL'] || getConfigValue('apiBaseUrl')
71+
if (isNonEmptyString(baseUrl)) {
72+
return baseUrl
73+
}
74+
// Lazily access constants.API_V0_URL.
75+
const API_V0_URL = constants.API_V0_URL
76+
return API_V0_URL
7377
}
7478

7579
export async function queryApi(path: string, apiToken: string) {

0 commit comments

Comments
 (0)