Skip to content

Commit dbefac8

Browse files
committed
Cleanup resultError
1 parent a9e0dea commit dbefac8

File tree

1 file changed

+7
-10
lines changed

1 file changed

+7
-10
lines changed

src/utils/api-helpers.ts

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -15,15 +15,12 @@ export function handleUnsuccessfulApiResponse<T extends SocketSdkOperations>(
1515
result: SocketSdkErrorType<T>,
1616
spinner: Spinner
1717
) {
18-
const resultError =
19-
'error' in result && result.error && typeof result.error === 'object'
20-
? result.error
21-
: {}
18+
// SocketSdkErrorType['error'] is not typed.
19+
const resultErrorMessage = (<{ error?: Error }>result).error?.message
2220
const message =
23-
'message' in resultError && typeof resultError.message === 'string'
24-
? resultError.message
21+
typeof resultErrorMessage === 'string'
22+
? resultErrorMessage
2523
: 'No error message returned'
26-
2724
if (result.status === 401 || result.status === 403) {
2825
spinner.stop()
2926
throw new AuthError(message)
@@ -51,17 +48,17 @@ export async function handleApiCall<T>(
5148

5249
export async function handleAPIError(code: number) {
5350
if (code === 400) {
54-
return `One of the options passed might be incorrect.`
51+
return 'One of the options passed might be incorrect.'
5552
} else if (code === 403) {
56-
return `You might be trying to access an organization that is not linked to the API key you are logged in with.`
53+
return 'You might be trying to access an organization that is not linked to the API key you are logged in with.'
5754
}
5855
}
5956

6057
export async function queryAPI(path: string, apiKey: string) {
6158
return await fetch(`${API_V0_URL}/${path}`, {
6259
method: 'GET',
6360
headers: {
64-
Authorization: 'Basic ' + btoa(`${apiKey}:${apiKey}`)
61+
Authorization: `Basic ${btoa(`${apiKey}:${apiKey}`)}`
6562
}
6663
})
6764
}

0 commit comments

Comments
 (0)